简体   繁体   English

Flutter 中的浮动操作按钮

[英]Floating Action Button in Flutter

I was trying to create the Floating Action button but I am missing icon.我试图创建浮动操作按钮,但我缺少图标。

My code is:我的代码是:

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

it is a screen from the virtual device.( You can see icon looks weird.)这是虚拟设备的屏幕。(你可以看到图标看起来很奇怪。) 在此处输入图像描述

To use this class, make sure you set uses-material-design: true in your project's pubspec.yaml file in the flutter section.要使用此类,请确保在项目的pubspec.yaml文件的 flutter 部分中设置uses-material-design: true This ensures that the MaterialIcons font is included in your application.这可确保您的应用程序中包含 MaterialIcons 字体。 This font is used to display the icons.此字体用于显示图标。 For example:例如:

在此处输入图像描述

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

The Icon is not rendering because of the missing font from the material design library.由于材料设计库中缺少字体,图标未呈现。 You have to enable the material design library in your pubspec.yml file as given below,您必须在pubspec.yml文件中启用材料设计库,如下所示,

flutter:
  uses-material-design: true

Just make uses-material-design to true and the error will be gone.只需将uses-material-design设置为true ,错误就会消失。 This ensures that the MaterialIcons font is included in your application.这可确保您的应用程序中包含 MaterialIcons 字体。 This font is used to display the icons Here is the official docs of Icon class此字体用于显示图标 这是Icon类的官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM