flutter-packages
flutter-packages copied to clipboard
[Proposal] Add function to await any pending font loads.
The addition of the pendingFontLoads function would allow users to request multiple google fonts, then asynchronously wait for the fonts to be loaded. For example, the following snippet will show a progress indicator until the fonts have finished loading, then it will load the page.
https://github.com/material-foundation/google-fonts-flutter/issues/151

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
GoogleFonts.oswald();
GoogleFonts.pacifico();
return MaterialApp(
home: FutureBuilder(
future: GoogleFonts.pendingFontLoads(),
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(child: CircularProgressIndicator());
}
return MyHomePage(title: 'Demo');
},
),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
final TextStyle headline4 = Theme.of(context).textTheme.headline4!;
return Scaffold(
appBar: AppBar(
title: Text(title, style: GoogleFonts.pacifico()),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'This is a google font',
style: GoogleFonts.oswald(textStyle: headline4),
),
],
),
),
);
}
}
Possible improvements would be:
- Making it so that the user can tell which font loads when.
- Making it so that the user doesn't have to call all the fonts before hand, maybe add a way to pass in the fonts they want to load.
instead of return a Future of List of fonts, can this return a List of Future fonts? Also, consider renaming to `loadedFonts, since they aren't necessarily pending when this is called
Hey @johnsonmh and @guidezpl, I would really appreciate if someone had the time to finish this PR in the near future.
It's an awesome feature, and you are doing amazing work 💙😄
Get me out of here!!
@johnsonmh is this still valid?
heyla! it's approved!! pls merge it
Hey @guidezpl, can you take another pass at this when you get a chance? Thanks!
It's been 2 years. What happened? Can we merge it? 😄
Generally how long does it take for a merge like this to be available in the package?
I'm going to fix https://github.com/material-foundation/flutter-packages/issues/102 and then release :)