How To Use Google Fonts In Your Flutter App

Flutter category image

Introduction

Google Fonts contains over 1,800 different fonts that are free to use. You’ll find the perfect font for any app in their repository. But how do you get them in your app? The usual way is to download the fonts, add them to your pubspec.yaml, and configure them in your app. But there is an easier way. So here is how to use Google Fonts in your Flutter app!


Install the package

Manually installing fonts is not hard, but it’s a bit annoying. The google_fonts package takes care of most of it. Install the package for your app.

Bash
# install with CLI
flutter pub add google_fonts
YAML
# add manually to pubspec.yaml
name: flutter_test
description: "A new Flutter project."
publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: ^3.8.1
  flutter: 3.35.2

dependencies:
  flutter:
    sdk: flutter
  flutter_web_plugins:
    sdk: flutter

  cupertino_icons: ^1.0.8
  google_fonts: ^6.3.1

This saves you from having to download and manually add the font files.


Apply the configuration

Next, head over to your main.dart (or the file where your MaterialApp instance is created).

Choose the desired font (for example, prompt) and assign the corresponding TextTheme object in your ThemeData constructor. This configures all properties in the TextTheme class to use that font. No matter if you want bodySmall or labelLarge, the font will always be the same!

Dart
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      ...
      theme: ThemeData(
        textTheme: GoogleFonts.promptTextTheme())
    );
}

And that is it!

All it takes is 1 minute of work. Compare this with the manual process!


Conclusion

In this article, you learned how to use Google Fonts in your Flutter app. While you can do everything manually, the google_fonts package offers a simple and fast solution to get the job done. I’d recommend using it whenever possible!



Want More Flutter Content?

Join my bi-weekly newsletter that delivers small Flutter portions right in your inbox. A title, an abstract, a link, and you decide if you want to dive in!

Flutter ❤️ Firebase

Get started with Firebase and learn how to use it in your Flutter apps. My detailed ebook delivers you everything you need to know! Flutter and Firebase are a perfect match!

Become A Testing Expert!

Become a proficient Flutter app tester with my detailed guide. This ebook covers everything from unit tests over widget tests up to dependency mocking.