【问题标题】:Floating Action Button in FlutterFlutter 中的浮动操作按钮
【发布时间】:2020-03-25 17:05:06
【问题描述】:

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

我的代码是:

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,
        ),
      ),
    );
  }
}

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

【问题讨论】:

    标签: flutter floating-action-button


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      flutter:
        uses-material-design: true
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-15
        • 2019-04-23
        • 2020-07-03
        • 2021-09-20
        • 2022-10-05
        • 2021-01-27
        • 2020-09-23
        • 2019-03-06
        相关资源
        最近更新 更多