Integrate Noto Serif KR into a Flutter app
I wanted to try out google_fonts and use it to display beautiful text in Korean. It was harder than the doc said.
I started according to the instructions at https://pub.dev/packages/google_fonts, adding the dependency to my pubspec.yaml, then using one of its predefined methods:
Text( '음악', style: GoogleFonts.notoSerif(), ),
It worked with latin letters but not with Korean hangul. So I tried with a Locale
Text( '음악', style: GoogleFonts.notoSerif(locale: Locale('kr')), ),
Didn't work either. Looking at the Google Fonts page for the font, the title is "Noto Serif KR", so I tried passing that String instead:
Text( '음악', style: GoogleFonts.getFont('Noto Serif KR'), ),
This time it threw an error telling me that the font family didn't exist.
So my last resort was bundling the file directly into my app according to https://pub.dev/packages/google_fonts#bundling-font-files-in-your-applications-assets. It says I can download the font, then extract the files to an assets folder, and declare that folder in my pubspec.yaml. It also says I don't need to explicitly declare the font family and the font files:
the files are consistently named from the Google Fonts API (so be sure not to rename them!)
Since I had downloaded the KR family, the font filename was
NotoSerifKR-[font weight].otf. I tried running it again. No luck. So my guess is that it won't look for localized fonts even if it's hosted. So I renamed my file to
NotoSerif-[font weight].otf. And finally, it worked!
I wish they had documented it all along. I'll submit a PR to update their docs when I get the chance.