I'm need to implement Times New Roman Font in my flutter project. I tried google_font packege but in that i didn't find any font.
Can anyone please help on this.
Thanks in Advance.
hi you can use Font from others source download add it in your project. check here for your font.
Add your font files into your project folder. Say Project Folder > assets > fonts > Times New Roman.
Declare the font family with font files with style in your project's pubspec.yaml file as (An example):
1.Download your custom fonts
2.Add it in your projects
3.Declare in your pubspec.yaml
flutter:
uses-material-design: true
fonts:
- family: Times
fonts:
- asset: assets/fonts/times/times.ttf
4.Call it your MaterialApp()
MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(fontFamily: 'Times'),
home: const LandingPage(),
);
Related
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
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.
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?
I want to use a default font family for my flutter app but according to the Flutter docs for setting a default font family we should declare it as a theme data in our MaterialApp instance
Text : To use a font as the default, set the fontFamily property as part of the app’s theme. The value provided to fontFamily must match the family name declared in the pubspec.yaml.
MaterialApp(
title: 'Custom Fonts',
// Set Raleway as the default app font.
theme: ThemeData(fontFamily: 'Raleway'),
home: MyHomePage(),
);
But I don't want to use MaterialApp for my app and I want to set a font as the default font of my application , any solution ?
No.
you can use your font anywhere that you want
Text("Helloo!",style:TextStyle(fontFamily:"font name"))
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'))