Flutter 中的浮动操作按钮

Cih*_*man 5 floating-action-button flutter

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

我的代码是:

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,
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

这是虚拟设备的屏幕。(你可以看到图标看起来很奇怪。) 在此输入图像描述

kri*_*aji 4

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

在此输入图像描述

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