I have added the font in pubspec.yaml Any True Type Font works just fine. But, when I add Open Type Font it doesn't work.
Here is my how I added font in pubspec.yaml
fonts:
- family: Kufyan
fonts:
- asset: assets/fonts/Kufyan.otf
The flutter recent version v1.12.13 does not support the open type font(otf) directly. You have to convert the otf to true type font(ttf) somehow. You can use this third-party website to covert the font to ttf before using it in your project. You can refer to the guide on how to use custom fonts in flutter for more information.
Flutter matches the font family based on the metadata in the font itself. So defining family: Kufyan is not required in pubspec.yml
Note: OTF is now officially supported, see supported font types
✔️ Officially works since 24 feb of 2021
Proofs
Since this commit (GitHub)
Current docs state look here (Flutter docs)
Just tested with Futter 1.20 and looks like OTF fonts work as expected. I can't seem to find anything in the docs about what type of fonts Flutter supports.
The Flutter engine matches fonts within a family based on the metadata in the font itself.
(We should remove the style descriptors in pubspec.yaml now that they are obsolete).
Declaring these fonts as different families in pubspec.yaml will work
around this.
Example can be seen here
which you have done.
But otf is may not be supported. it can be because of google fonts.
If its still not working then...
There is a trick you can use which is to convert otf to ttf via a
third party i.e. convertio etc.
Then you can use it as a normal font.
Import the font files.
Declare the font in the pubspec.
Set a font as the default.
Use a font in a specific widget.
The Flutter engine matches fonts within a family based on the metadata in the font itself, not the style descriptors declared in the pubspec.yaml manifest.
(We should remove the style descriptors in pubspec.yaml now that they are obsolete).
The Edmondsans regular, medium, and bold fonts contain metadata declaring their weights as 400, 410, and 420 respectively. However, the Flutter text subsystem only supports font weight buckets representing even multiples of 100 (https://api.flutter.dev/flutter/dart-ui/FontWeight-class.html). So all three of these fonts are mapped to FontWeight.w400, and the font style matcher can not choose between these fonts based on weight.
Declaring these fonts as different families in pubspec.yaml will work around this.
Convert otf font file in ttf font file using this platform. https://convertio.co/otf-ttf/
Import the font files.
Declare the font in the pubspec.
Set a font as the default.
Use a font in a specific widget.
Here is the example and steps to use custom font.
https://www.xam-consulting.com/blog/adding-custom-fonts-in-flutter-application
iam using a custom arabic font for my app
but sometimes the data that coming from the server come in english
the problem is that the custom arabic font not changing the english
letter font to the main font like what is happening in android
i used the localization to determine the language of the app but it didnt success
because i think that the app language didnt change
its just the letters
so i think if i could determine the language of the text then choose the font for it
or using a font that supporting arabic or english
but is there any better solution?
thank u
I have done localization of iPhone project in english,german and french language.French and english are working fine with change of language on iPhone/simulator but german language is not working properly.
I have changed texts in the xib file for each language under the localization.
Whenever i am trying to change language to german(Belgium),XIB file with english text is getting shown on the simulator/iphone.
I have tried changing region first(belgium) and then language(German) but have no luck with it.
Please help me for the same.
Thanks in advance.
I installed a custom font however, my app runs on two languages. I noticed that the custom fonts work with English but not with non-English. How can I overcome this?
You need to choose a custom font that includes "glyphs" for all of the special characters and punctuation that are needed for the language you are using. If the custom font you have is missing these extra glyphs, then you can either edit the font in a font editor such as Fontographer to add the missing glyphs (this requires drawing them in or copying parts from other letters), or finding a new version of the same font that includes the glyphs you need.
You can see the missing glyphs by opening a font that has these glyphs in the "Font Book" program included with mac os x. Then you can open your custom font and compare the two to see what's missing.
Also keep in mind that you usually need a custom license from the font owner to include fonts in your application.
I know how to use custom fonts to display CCLabels. I also figured out how to localize the Labels. But I am wondering if there is anyway to display the localized text using custom fonts.
For example when I use Arial I have no problems, the chinese fonts appear correctly. But when I use a font not included in XCode such as ARLRDBD.TTF then the chinese characters do not get displayed.
How can I display the chinese characters in ARLRDBD.TTF too? Or am I stuck with just using the default fonts included in XCode if I plan to use LocalizedString?
Thanks
Abhinav
You should be able to use any font that has Chinese characters in it.
Not all fonts include characters for all languages. Many Western fonts only have the Roman alphabet (A-Z).
You could either use a font that has all the characters you will need (like Arial, or another Unicode font - see: http://en.wikipedia.org/wiki/Unicode_typeface), or have separate fonts for each language.
I'd suggest a different font for each language.
You could keep it organized with a simple struct.
typedef struct {
NSString *regionname;
NSString *fontname;
} RegionFont;
//later in the code....
RegionFont some_region;
some_region.regionname = #"China";
some_region.fontname = #"Arial";
You can test if a font supports a given language by opening Font Book (standard Mac app) and searching under "All Fonts" for the language you want.
I don't have many custom fonts installed and several with Chinese support come up.
Hope this helps.
You can use custom fonts in your app but you need to make the system aware that they exist using the UIAppFonts key in your Info.plist file. See here for more information.