Flutter not applying custom fonts - flutter

I am trying to use custom fonts in my flutter app, I did what i always do, and even trying to see many tutorials to see if i am missing something
1- added the ttf files to 'assets/fonts' (trying to upload an image but getting server error here)
2- added these to pubspec.yaml
uses-material-design: true
fonts:
- family: karashi
fonts:
- asset: assets/fonts/Karashi.ttf
- family: Hafs
fonts:
- asset: assets/fonts/Hafs.otf
- family: Qarwan
fonts:
- asset: assets/fonts/Qarwan.ttf
- family: suranames
fonts:
- asset: assets/fonts/suranames.ttf
3- used TextStyle to apply the font family
appBar: AppBar(
title: Text(
'استقلال ',
style: TextStyle(
fontFamily: 'Qarwan', color: Colors.red, fontSize: 40),
),
the result is that the font does not change and stays on the default font, only if I used 'Hafs' font or 'suranames' font these two work while the others don't.
I tried changing only the file name of 'Hafs' and put another file, but still wont work
I restarted the app, uninstalled then installed, restarted computer but nothing works
what could be the issue and how can I fix it?
thanks

Related

fonts on pubspec.yaml, doesn't display my font correctly

i recently change pubspec.yaml file but flutter can't display my font
fonts:
- family: Amatic
fonts:
- asset: assets/fonts/Amatic-Bold.ttf
- asset: assets/fonts/Amatic-Regular.ttf
inside your GetMaterialApp at the main file inside theme you should add
fontFamily: 'The name of your font in the assets'
.yaml files are case sensitive. So, you have to give us your pubspec.yaml file as it is.
If you are not formatting the content as it should be, you will no get what you expect. ‎ ‎ ‎

Lost Connection to device as soon as I used custom fonts

This is the code inside the .YML file
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- Images/
fonts:
- family: Pacifico
fonts:
- asset: Fonts/Pacifico-Regular.ttf
and this is the part that I added before losing connection and crashes.
Text(
'Abdulrahman Hejazi',
style: TextStyle(
fontSize: 25,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Pacifico'
),
),
I noticed something, that If I build (run) the project from the start it crashes, but if I hot reload it, it works just fine.
you need to rename asset folder Fonts to lower case fonts because capital letters are not allowed in folder names
It may be either of the following:
Your font file name has space on it. If yes remove it.
Your font file name may be misspelled.
Your font file may be corrupted.Try adding new one.
PS. does it load the font when hot reload or it doesn't?

Full list of font families provided with Flutter?

In Flutter we can use TextStyle to provide a desired fontFamily property for the text.
While some fontFamily names are obvious and do work (like 'Arial', 'Courier', 'Times' and so on), where's the full list of available options?
The docs (https://api.flutter.dev/flutter/painting/TextStyle/fontFamily.html) don't help.
I do not think such a list is provided by the Flutter team. The fonts you mention are probably system default fonts. Flutter handles the use of custom fonts with a 'Custom Font Fallback'. Listed below is a tool snippet of how this goes to work:
Snippet
In the following example, any glyphs not present in the font Raleway will be attempted to be resolved with Noto Sans CJK SC, and then with Noto Color Emoji:
const TextStyle(
fontFamily: 'RaleWay',
fontFamilyFallback: <String>[
'Noto Sans CJK SC',
'Noto Color Emoji',
],
)
If all custom fallback font families are exhausted and no match was found
or no custom fallback was provided, the platform font fallback will be used.
Since you do not provide any FallBack fonts, Flutter automatically uses the the fonts default to your system of choice.
I hope this you understand what happens now! Please look at the documentation on how to add custom fonts:
Flutter font documentation
You don´t need to worry about the default fonts.
You can download a font that you like from here https://fonts.google.com/
Then add it to your assets folder, and update your pubspec.yaml
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
fonts:
- family: yourFont
fonts:
- asset: assets/fonts/yourFont.ttf
- family: otherFont
fonts:
- asset: assets/fonts/otherFont.ttf
After that, you can use it like this:
Text('Some text',
style: TextStyle(
color: Colors.blue,
fontFamily: 'yourFont',
fontSize: 22.0,
),
),
I recently encountered the same problem with fonts and Flutters incomplete documentation of font list.
A much easier solution for me was to import Google's font library:
//Import the font package
import 'package:google_fonts/google_fonts.dart';
//Use the Font package instead of TextStyle with your custom tweeks
Text('Sign Up',
style: GoogleFonts.poppins(
color: const Color.fromARGB(255, 59, 59, 61),
fontSize: 64,
fontWeight: FontWeight.w900,
),
),
And the list of fonts offered by this library is HUGE.
check them out with complete examples from here:
https://fonts.google.com/

How to embed webfont using font URL in flutter application

How to use font-URL to embed webfonts in flutter application ?
As per the requirement I can't use custom font as below :
flutter:
fonts:
- family: Raleway
fonts:
- asset: fonts/Raleway-Regular.ttf
Can anyone please let me know how to use fonts directly from URL ?
Because of flutter for web still in technical preview maybe in the future it won't work. But for now (in my case Flutter 1.10.14 dev) we can reference font from url as in a normal web page.
Add to the head section of index.html file from web folder:
<link href="https://fonts.googleapis.com/css?family=Raleway&display=swap" rel="stylesheet">
and reference font from code like:
Text( 'Example', style: TextStyle(fontFamily: 'Raleway'))

unable to add fonts in flutter

I am trying to add custom fonts in my flutter app. I have added fonts in pubspec.yaml
flutter:
fonts:
- family: Quicksand
fonts:
- asset: assets/fonts/Quicksand-Regular.ttf
Aslo I have added this in my Text widget
style: TextStyle(
color: Colors.white,
fontSize: 80.0,
fontFamily: 'Quicksand',
),
I am not getting any error, but my font is not getting applied.
Make sure you Re-Build the Project Again - Hot-Restart Won't work & do run flutter packages get
when you add the font to youre project. first, you must restart your app after that its work normally .its important not using Hot Reload in this case! for the first time