[英]Floating Action Button in 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,
),
),
);
}
}
要使用此类,请确保在项目的pubspec.yaml文件的 flutter 部分中设置uses-material-design: true 。 这可确保您的应用程序中包含 MaterialIcons 字体。 此字体用于显示图标。 例如:
请参考此链接: https ://api.flutter.dev/flutter/material/Icons-class.html
由于材料设计库中缺少字体,图标未呈现。 您必须在pubspec.yml
文件中启用材料设计库,如下所示,
flutter:
uses-material-design: true
只需将uses-material-design
设置为true
,错误就会消失。 这可确保您的应用程序中包含 MaterialIcons 字体。 此字体用于显示图标 这是Icon
类的官方文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.