talira

google_fonts

A Flutter package to use fonts from fonts.google.com

open sourceBSD-3-Clausefree

google_fonts is the Flutter team's package for using any font from Google Fonts in a Flutter app by name, as a TextStyle (GoogleFonts.lato()) or a whole TextTheme. It fetches font files over HTTP at runtime and caches them on the device's file system, and when matching font files are bundled in the app's assets it uses those instead, so a release build can work offline with no fetching. A GoogleFontsLite entry point resolves fonts dynamically so the compiler can tree-shake the generated font methods and keep the app smaller. It's part of the flutter/packages repository and published on pub.dev by flutter.dev.

Problems it solves

  • use a font from fonts.google.com in my Flutter app without downloading and declaring the font files by hand
  • try different fonts in a Flutter app with hot reload before picking one
  • switch my whole Flutter app's text theme to one typeface in a line of code
  • bundle the fonts my Flutter app uses in its assets so it works offline in production
  • load fonts on demand at runtime to keep my Flutter app's download size small
  • avoid text flashing in a fallback font while a web font loads in Flutter

Features

  • Any Google Fonts family as a TextStyle or TextTheme by name
  • Fetches fonts over HTTP at runtime and caches them on the device
  • Uses matching font files bundled in assets before fetching
  • HTTP fetching can be turned off entirely
  • GoogleFontsLite entry point for tree-shaking unused fonts
  • pendingFonts() to wait for fonts and avoid visual font swaps
  • Android, iOS, Linux, macOS, web and Windows