Flutter 颤振中的浮动动作按钮

Flutter 颤振中的浮动动作按钮,flutter,floating-action-button,Flutter,Floating Action Button,我试图创建浮动动作按钮,但缺少图标 我的代码是: import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: fa

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

我的代码是:

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,
        ),
      ),
    );
  }
}
这是来自虚拟设备的屏幕。(您可以看到图标看起来很奇怪。)

若要使用此类,请确保在项目的pubspec.yaml文件的“颤振”部分中设置使用材质设计:true。这可确保应用程序中包含MaterialIcons字体。此字体用于显示图标。例如:


请参阅此链接:

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

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:
  uses-material-design: true
只要将
使用材料设计
设置为
,错误就会消失。这可确保应用程序中包含MaterialIcons字体。此字体用于显示图标这里是
图标
类的官方名称