简体   繁体   中英

Flutter theme fontFamily not working. It only works as widget property

My app theme fontFamily is not changing anything. If I input it in a Text widget, it works like it should.

My pubspec.yaml is set up like this

fonts:
- family: Gilroy
  fonts:
   - asset: fonts/Gilroy-Light.otf
   - asset: fonts/Gilroy-ExtraBold.otf
     weight: 700

And my MaterialApp is

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. Text("Hello World", style: TextStyle(fontFamily: "Gilroy") works fine and there are no errors generated.

textTheme: Theme.of(context).textTheme.apply(
        fontFamily: fontFamily,
        bodyColor: Colors.white,
        displayColor: Colors.white,
      ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM