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.
- Step1: Add a font to your 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 tokhmerhand_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 theTextStyle
widget to whatever you called it in pubspec.yaml. For this example, I called itKhmerhandScript
.
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
0 Comments