0

I want to add a custom font to a specific widget, I did everything but it is not changing I imported the font files into the project and created a "fonts" folder for it then declared the font in the pubspec

I am using PlayfairDisplay and I've tried Roboto but it is still not changing

uses-material-design: true
fonts:
  - family: PlayfairDispaly
    fonts:
      - asset: fonts/PlayfairDisplay-Bold.ttf
        style: bold
Anshu
  • 1,277
  • 2
  • 13
  • 28
Goldfish5
  • 1
  • 2

2 Answers2

0

You may incorrectly defined the Font Family name

  • family: PlayfairDispaly fonts: - asset: fonts/PlayfairDisplay-Bold.ttf style: bold

you should write it as PlayfairDisplay not PlayfairDispaly

as maybe you use it in your widget with this code :

Text(
  "Hello World",
  style: TextStyle(
    fontFamily: "PlayfairDisplay",
  ),
),
ejabu
  • 2,998
  • 23
  • 31
0

When using google fonts in flutter you must take care of the spaces and the tabs, also you should make sure that the font family name is exactly the same 'case sensitive' in both the dart file and the pubspec.yaml file

the main.dart file should has a code like this :-

Text(
  'FullStack Developer',
   style: TextStyle(
   fontSize: 20.0,
   color: Colors.black,
   fontFamily: 'Playfair Display',
   letterSpacing: 2.0,
   fontWeight: FontWeight.bold,
   ),
  ),

and for the pubspec.yaml try this:-

flutter:
uses-material-design: true
fonts:
  - family: PlayfairDisplay
    fonts:
      - asset: fonts/PlayfairDisplay-Regular.ttf
AdnanAsali
  • 139
  • 2
  • 8