search

New

6/recent/ticker-posts

How to use a custom font in a Flutter app

Font style is very powerful for designer. It can make the website or app look so interesting from viewers. Here are a simple tip to make you easy with creating your owns fonts style on flutter project.

  • Right click on your project folder and go to New > Directory. Call it assets. It should be in your projects root directory.
  • Copy and paste your font into the new assets directory. I'm just using a single font in my example, the regular khmerhand script font. I renamed it to khmerhand_script.ttf.

- Step2: Register the font

  • Open your pubspec.yaml file.
  • Add the fonts info under the flutter section. Indentation is mandatory.
flutter:
fonts:
- family: KhmerhandScript
fonts:
- asset: assets/khmerhand_script.ttf

- Step2: Use the font in your theme or widget

  • Now you can use your font by setting the fontFamily attribute in the TextStyle widget to whatever you called it in pubspec.yaml. For this example, I called it KhmerhandScript.
Text(
'Hello world',
style: TextStyle(
fontFamily: 'KhmerhandScript',
),
)

- Step4: Restart your app

  • Whenever I add assets I find I need to do a full stop and rest

Post a Comment

0 Comments

Contact Form

Name

Email *

Message *

Random Products

Learning English