I am using Flutter Web (which is currently in beta) and it seems that the FontWeight
of the Text
Widget is not working properly while using GoogleFonts.
The problem does not exist when the default Font is used.
Project:
The project was created with the following commands
flutter channel beta
flutter upgrade
flutter config --enable-web
flutter create web_font_not_working
Example Code:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
textTheme: GoogleFonts.montserratTextTheme()),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'This text should be bold',
style: TextStyle(fontWeight: FontWeight.bold),
),
Text('This text is normal'),
],
));
}
}
Result of the Example Code:
Side effects:
When saving the code, the browser refreshes as expected and shows a bold text for a short time. After the page is fully loaded the website looks as shown above.
Question(s):
The question is now obsolete.
I am currently using flutter 1.21.0-9.1.pre
and google_fonts
is working as expected.
If you have a similar problem upgrade to the most recent flutter version.