{"id":15067706,"url":"https://github.com/amake/dynamic-fonts-flutter","last_synced_at":"2025-10-23T06:20:13.225Z","repository":{"id":52239440,"uuid":"283498741","full_name":"amake/dynamic-fonts-flutter","owner":"amake","description":"A Flutter package for dynamically loading web-hosted fonts","archived":false,"fork":true,"pushed_at":"2024-03-04T13:38:54.000Z","size":10475,"stargazers_count":20,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-30T12:05:00.102Z","etag":null,"topics":["flutter","fonts"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/dynamic_fonts","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"material-foundation/flutter-packages","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amake.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-29T12:54:49.000Z","updated_at":"2024-06-07T05:23:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/amake/dynamic-fonts-flutter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fdynamic-fonts-flutter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fdynamic-fonts-flutter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fdynamic-fonts-flutter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amake%2Fdynamic-fonts-flutter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amake","download_url":"https://codeload.github.com/amake/dynamic-fonts-flutter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235365172,"owners_count":18978317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flutter","fonts"],"created_at":"2024-09-25T01:26:16.052Z","updated_at":"2025-10-05T05:30:32.074Z","avatar_url":"https://github.com/amake.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dynamic_fonts\n\nThe `dynamic_fonts` package for Flutter allows you to (relatively) easily add\ndynamically loaded web-hosted fonts to your appーjust like the\n[google_fonts](https://pub.dev/packages/google_fonts) package, but for any\narbitrary fonts hosted anywhere.\n\n`dynamic_fonts` is a fork of `google_fonts` with more of the API exposed so that\nyou can specify your own fonts.\n\n## Why would you use this?\n\nIf there is a font that you know you're going to use in your app, just bundle it\nnormally. Don't bother with this package.\n\nBut if your app e.g. offers users multiple choices of fonts, and\n\n1. Some fonts may not be used at all, depending on user preferences\n2. Bundling all of the fonts would bloat your app too much\n\nthen this package gives you a convenient way to load your fonts dynamically and\nkeep your initial download slim.\n\n## Getting Started\n\nWith the `dynamic_fonts` package, `.ttf` or `.otf` files do not need to be\nstored in your assets folder and mapped in the pubspec. Instead, they can be\nfetched once via http at runtime, and cached in the app's file system. This is\nideal for development, and can be the preferred behavior for production apps\nthat are looking to reduce the app bundle size. Still, you may at any time\nchoose to include the font file in the assets, and the Dynamic Fonts package\nwill prioritize pre-bundled files over http fetching.  Because of this, the\nDynamic Fonts package allows developers to choose between pre-bundling the fonts\nand loading them over http, while using the same API.\n\nFor example, say you want to use the\n[FiraGO](https://github.com/bBoxType/FiraGO) font (*not* in Google Fonts) in\nyour Flutter app.\n\nFirst, add the `dynamic_fonts` package to your [pubspec\ndependencies](https://pub.dev/packages/dynamic_fonts#-installing-tab-).\n\nTo import `DynamicFonts`:\n\n```dart\nimport 'package:dynamic_fonts/dynamic_fonts.dart';\n```\n\n### Registering a font\n\nTo register your font with `DynamicFonts`, you will need to supply the family\nname and a map of `DynamicFontsVariant` to `DynamicFontsFile`.\n\n- `DynamicFontsVariant` merely indicates font weight and font style (normal vs\n  italic)\n- `DynamicFontsFile` stores checksum info and provides the URL for the file\n\nIf we want to download FiraGO from the repo hosted on GitHub (*don't do this in\na production app!*), the URL depends on the variant, so we need to do something\nlike this:\n\n```dart\nclass FiraGoFile extends DynamicFontsFile {\n  FiraGoFile(this.variant, String expectedFileHash, int expectedLength)\n      : super(expectedFileHash, expectedLength);\n\n  final DynamicFontsVariant variant;\n\n  String get _dir {\n    switch (variant.fontStyle) {\n      case FontStyle.normal:\n        return 'Roman';\n      case FontStyle.italic:\n        return 'Italic';\n    }\n    throw Exception('Unknown style: ${variant.fontStyle}');\n  }\n\n  @override\n  String get url =\u003e\n      'https://raw.githubusercontent.com/bBoxType/FiraGO/9882ba0851f88ab904dc237f250db1d45641f45d/Fonts/FiraGO_TTF_1001/$_dir/FiraGO-${variant.toApiFilenamePart()}.ttf';\n}\n```\n\nNow we can register the font like so, supplying the SHA256 and file sizes for\nsecurity. (Actual SHA256 values not shown!)\n\n```dart\nDynamicFonts.register(\n  'FiraGO',\n  [\n    FiraGoFile(\n      const DynamicFontsVariant(\n        fontWeight: FontWeight.w400,\n        fontStyle: FontStyle.normal,\n      ),\n      '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',\n      804888,\n    ),\n    FiraGoFile(\n      const DynamicFontsVariant(\n        fontWeight: FontWeight.w700,\n        fontStyle: FontStyle.normal,\n      ),\n      '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',\n      807140,\n    ),\n    FiraGoFile(\n      const DynamicFontsVariant(\n        fontWeight: FontWeight.w400,\n        fontStyle: FontStyle.italic,\n      ),\n      '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',\n      813116,\n    ),\n  ].fold\u003cMap\u003cDynamicFontsVariant, DynamicFontsFile\u003e\u003e(\n    {},\n    (acc, file) =\u003e acc..[file.variant] = file,\n  ),\n);\n```\n\n### Using a font\n\nTo use `DynamicFonts` with the default TextStyle:\n\n```dart\nText(\n  'This is Dynamic Fonts',\n  style: DynamicFonts.getFont('FiraGO'),\n),\n```\n\nTo use `DynamicFonts` with an existing `TextStyle`:\n\n```dart\nText(\n  'This is Dynamic Fonts',\n  style: DynamicFonts.getFont(\n    'FiraGO', textStyle: TextStyle(color: Colors.blue, letterSpacing: .5),\n  ),\n),\n```\n\nor\n\n```dart\nText(\n  'This is Dynamic Fonts',\n  style: DynamicFonts.getFont('FiraGO', textStyle: Theme.of(context).textTheme.headline4),\n),\n```\n\nTo override the `fontSize`, `fontWeight`, or `fontStyle`:\n\n```dart\nText(\n  'This is Dynamic Fonts',\n  style: DynamicFonts.getFont(\n    'FiraGO',\n    textStyle: Theme.of(context).textTheme.headline4,\n    fontSize: 48,\n    fontWeight: FontWeight.w700,\n    fontStyle: FontStyle.italic,\n  ),\n),\n```\n\nYou can also use `DynamicFonts.getTextTheme()` to make or modify an entire text\ntheme to use the \"FiraGO\" font.\n\n```dart\nMaterialApp(\n  theme: ThemeData(\n    textTheme: DynamicFonts.getTextTheme(\n      'FiraGO',\n      Theme.of(context).textTheme,\n    ),\n  ),\n);\n```\n\nOr, if you want a `TextTheme` where a couple of styles should use a different\nfont:\n\n```dart\nfinal textTheme = Theme.of(context).textTheme;\n\nMaterialApp(\n  theme: ThemeData(\n    textTheme: DynamicFonts.getTextTheme('FiraGO', textTheme).copyWith(\n      body1: DynamicFonts.getFont('OtherFont', textStyle: textTheme.body1),\n    ),\n  ),\n);\n```\n\n### Bundling font files in your application's assets\n\nThe `dynamic_fonts` package will automatically use matching font files in your\n`pubspec.yaml`'s `assets` (rather than fetching them at runtime via HTTP). Once\nyou've settled on the fonts you want to use:\n\n1. Download the font files from wherever.  You only need to download the weights\nand styles you are using for any given family.  Italic styles will include\n`Italic` in the filename. Font weights map to file names as follows:\n\n```dart\n{\n  FontWeight.w100: 'Thin',\n  FontWeight.w200: 'ExtraLight',\n  FontWeight.w300: 'Light',\n  FontWeight.w400: 'Regular',\n  FontWeight.w500: 'Medium',\n  FontWeight.w600: 'SemiBold',\n  FontWeight.w700: 'Bold',\n  FontWeight.w800: 'ExtraBold',\n  FontWeight.w900: 'Black',\n}\n```\n\n2. Move those fonts to a top-level app directory (e.g. `dynamic_fonts`).\n\n3. Ensure that you have listed the folder (e.g. `dynamic_fonts/`) in your\n   `pubspec.yaml` under `assets`.\n\nNote: If your fonts' names do not match up with the Google Font naming\nconventions, you will either have to register them in the `fonts` section of\n`pubspec.yaml`, or rename them.\n\n### Licensing Fonts\nBe sure to check the licenses of your fonts. For instance FiraGO comes with an\n`OFL.txt` file.\n\nOnce you've decided on the fonts you want in your published app, you should add\nthe appropriate licenses to your flutter app's\n[LicenseRegistry](https://api.flutter.dev/flutter/foundation/LicenseRegistry-class.html).\n\nFor example:\n```dart\nvoid main() {\n  LicenseRegistry.addLicense(() async* {\n    final license = await rootBundle.loadString('dynamic_fonts/OFL.txt');\n    yield LicenseEntryWithLineBreaks(['dynamic_fonts'], license);\n  });\n\n  runApp(...);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famake%2Fdynamic-fonts-flutter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famake%2Fdynamic-fonts-flutter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famake%2Fdynamic-fonts-flutter/lists"}