Flutter custom font not getting applied
1,908
As mentioned in the flutter website: https://flutter.dev/docs/cookbook/design/fonts
Folder Structure:
your_app/
fonts/
Raleway-Regular.ttf
Raleway-Italic.ttf
RobotoMono-Regular.ttf
RobotoMono-Bold.ttf
Declare in pubspec.yaml:
flutter:
fonts:
- family: Raleway
fonts:
- asset: fonts/Raleway-Regular.ttf
- asset: fonts/Raleway-Italic.ttf
style: italic
- family: RobotoMono
fonts:
- asset: fonts/RobotoMono-Regular.ttf
- asset: fonts/RobotoMono-Bold.ttf
weight: 700
You are using asset prefix while declaring, I think it's the problem !
Author by
bensofter
Updated on December 15, 2022Comments
-
bensofter over 1 year
Am trying to set a custom font to my
Text
inFlutter
. I have tried everything I know but it didn't work. Is this a bug or something?flutter: uses-material-design: true assets: - assets/images/onboarding1.png - assets/images/onboarding2.png - assets/images/onboarding3.png fonts: - family: Gilroy fonts: - asset: assets/fonts/gilroy_extrabold.otf
Dart File
SizedBox(height: 30.0), Text( 'Connect with Mentors', style: TextStyle( fontFamily: 'Gilroy', fontSize: 35.0, ), ),
-
user5269602 almost 4 yearsWhat about if we're building for web? Seems like for hosted web you have to have the fonts in a web/assets folder.
-
userRR over 3 years@user5269602 when building/compiling for the web it also takes the font from the folder.
-
chk.buddi over 3 years@naveen-avidi Even with - asset: fonts/IndieFlower-Regular.ttf , I got the same issue