Flutter中的浮动操作按钮

问题描述 投票:1回答:2

我曾尝试创建“浮动操作”按钮,但缺少图标。

我的代码是:

import 'package:flutter/material.dart';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.blue,
          centerTitle: true,
          title: Text(
            "Lessons of Flutter",
            style: TextStyle(
              color: Colors.white,
            ),
          ),
        ),
        body: Center(
            child: const Text('Press the button below!')
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            // Add your onPressed code here!
          },
          child: Icon(Icons.mouse),
          backgroundColor: Colors.green,
        ),
      ),
    );
  }
}

这是虚拟设备的屏幕。(您可以看到图标看起来很奇怪。)enter image description here

flutter floating-action-button
2个回答
0
投票

要使用此类,请确保在flutter部分的项目的pubspec.yaml文件中设置uses-material-design:true。这样可以确保MaterialIcons字体包含在您的应用程序中。该字体用于显示图标。例如:

enter image description here

请参阅此链接: https://api.flutter.dev/flutter/material/Icons-class.html


0
投票

由于材质设计库中缺少字体,因此图标未呈现。您必须按如下所示在pubspec.yml文件中启用材料设计库,

flutter:
  uses-material-design: true

只需将uses-material-design设置为true,错误就会消失。这样可以确保MaterialIcons字体包含在您的应用程序中。该字体用于显示图标。这是docs类的官方Icon

© www.soinside.com 2019 - 2024. All rights reserved.