appbar中的标题字体在flutter中不改变



void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext) {
return MaterialApp(
title: 'soshia',
home: Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.red,
title: Text('soshia', style: TextStyle(fontFamily: 'Festive')),
centerTitle: true,
leading: Icon(Icons.chat),
actions: [
Padding(
padding: EdgeInsets.only(right: 16.0),
child: Icon(Icons.search),
),
],
),
),
);
}
}

这是我的代码。我已经尝试了很多,但我不能理解为什么我的appbar的标题字体没有改变。我已经将font .ttf文件保存在fonts文件夹中。我也更新了我的pubspec。ymal代码。下面是我的公共邮箱。请帮助。

description: A new Flutter project.

publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter

cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter:
uses-material-design: true
fonts:
- family: Festive
fonts:
- asset: fonts/Festive-Regular.ttf```

试着给material小部件添加theme属性,这样你就可以在整个小部件上使用这个字体族了:

void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext) {
return MaterialApp(
title: 'soshia',
theme: ThemeData(
fontFamily: 'Festive',),
home: Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.red,
title: Text('soshia'),
centerTitle: true,
leading: Icon(Icons.chat),
actions: [
Padding(
padding: EdgeInsets.only(right: 16.0),
child: Icon(Icons.search),
),
],
),
),
);
}

}

最新更新