class MyApp extends StatelessWidget { const MyApp({Key key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'Icon字体图标', home: Scaffold( appBar: AppBar( title: Text('Icon字体图标'), ), body: Column( children: [ Icon( //这里的Icons其实就是Material内置的字体图标 // Icons.favorite, --------> 等同于 IconData(0xe87d, fontFamily: 'MaterialIcons', matchTextDirection: true) IconData( //code 0xe87d, //字体,在pubspec.yaml定义 fontFamily: 'MaterialIcons', matchTextDirection: true), ), Icon( IconData( //code 61447, //字体,在pubspec.yaml定义 fontFamily: 'FontAwesome', ), size: 40.0, ), ], ), ), ); } }
Flutter笔记28:Icon字体图标
Flutter的IconData可以自定义字体图标,Flutter的Icons自带的字体图标其实就是封装的IconData。通过在pubspec.yaml引入图标字体,再通过IconData去调用具体的字体代码和字体名称即可实现自定义字体: