Naming Font Files
The file name for a font must match the PostScript name of the font for your flows to properly load the custom font on both Android and iOS. This is because in native Android apps, fonts are referenced by their resource name (which is the filename1), while in native iOS apps, fonts are referenced by their PostScript name2. On macOS, you can find the PostScript name of a font by opening it with the Font Book app and selecting the Font Info tab.Android Setup
For an Android app, the font files need to be copied to the expected directory:android/app/src/main/assets/fonts.
Maintaining a Single Source of Truth for Font Files
To maintain a single source of truth for your font files, it is recommended to move the font files fromfonts to android/app/src/main/assets/fonts and then update pubspec.yaml with the new path:
pubspec.yaml.
iOS Setup
For an iOS app, the font files need to be added to the Runner target in your Xcode project and be added to<UIAppFonts> in Info.plist3.
Step 1. Add Font Files to Xcode Project
- Open the
Runner.xcodeprojfile in Xcode. - Select File > Add Files to “Runner”.
- Navigate to
android/app/src/main/assets/fontsin the file picker and select all font files. - Ensure
Runneris checked for the Add to targets: option. - Click Add.
ios/Runner/Info.plist and add an array entry for <UIAppFonts> with a value for each font file name:
Summary
Your project should look like this:Footnotes
- “The resource name, which is either the filename excluding the extension…” https://developer.android.com/guide/topics/resources/providing-resources ↩
-
“When retrieving the font with
custom(_:size:), match the name of the font with the font’s PostScript name.” https://developer.apple.com/documentation/swiftui/applying-custom-fonts-to-text/#Apply-a-font-supporting-dynamic-sizing ↩ - Refer to https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app ↩