Flutter 中的浮动操作按钮
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,
),
),
);
}
}
这是虚拟设备的屏幕。(你可以看到图标看起来很奇怪。)
要使用此 class,请确保在项目的 [=24] 中设置 uses-material-design: true =] 文件中的 flutter 部分。这确保 MaterialIcons 字体包含在您的应用程序中。此字体用于显示图标。例如:
参考这个link: https://api.flutter.dev/flutter/material/Icons-class.html
图标未呈现,因为 material 设计库中缺少字体。您必须在 pubspec.yml
文件中启用 material 设计库,如下所示,
flutter:
uses-material-design: true
只需将uses-material-design
改为true
,错误就会消失。这确保 MaterialIcons 字体包含在您的应用程序中。这个字体是用来显示图标的 这里是Icon
class
的官方docs
我试图创建浮动操作按钮,但缺少图标。
我的代码是:
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,
),
),
);
}
}
这是虚拟设备的屏幕。(你可以看到图标看起来很奇怪。)
要使用此 class,请确保在项目的 [=24] 中设置 uses-material-design: true =] 文件中的 flutter 部分。这确保 MaterialIcons 字体包含在您的应用程序中。此字体用于显示图标。例如:
参考这个link: https://api.flutter.dev/flutter/material/Icons-class.html
图标未呈现,因为 material 设计库中缺少字体。您必须在 pubspec.yml
文件中启用 material 设计库,如下所示,
flutter:
uses-material-design: true
只需将uses-material-design
改为true
,错误就会消失。这确保 MaterialIcons 字体包含在您的应用程序中。这个字体是用来显示图标的 这里是Icon
class