[英]Flutter theme fontFamily not working. It only works as widget property
My app theme fontFamily is not changing anything.我的应用主题 fontFamily 没有改变任何东西。 If I input it in a Text widget, it works like it should.如果我在 Text 小部件中输入它,它会正常工作。
My pubspec.yaml is set up like this我的 pubspec.yaml 是这样设置的
fonts:
- family: Gilroy
fonts:
- asset: fonts/Gilroy-Light.otf
- asset: fonts/Gilroy-ExtraBold.otf
weight: 700
And my MaterialApp is我的 MaterialApp 是
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(
const MyApp(),
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => MediaManager()),
],
child: StreamProvider<User?>.value(
value: Authentication().userStream,
initialData: null,
child: MaterialApp(
title: 'MyApp',
theme: ThemeData(
fontFamily: 'Gilroy',
scaffoldBackgroundColor: Colors.black,
textTheme: Theme.of(context).textTheme.apply(
bodyColor: Colors.white,
displayColor: Colors.white,
),
),
I tried to flutter clean
, uninstalling the app, restarting the emulator and I don't have another MaterialApp
set up.我试图flutter clean
,卸载应用程序,重新启动模拟器,但我没有设置另一个MaterialApp
。 Text("Hello World", style: TextStyle(fontFamily: "Gilroy")
works fine and there are no errors generated. Text("Hello World", style: TextStyle(fontFamily: "Gilroy")
工作正常,没有产生错误。
textTheme: Theme.of(context).textTheme.apply(
fontFamily: fontFamily,
bodyColor: Colors.white,
displayColor: Colors.white,
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.