Working with text
Domains:
Flutter
How do I set custom fonts on my text widgets?
In Xamarin.Forms, you would have to add a custom font in each native project. Then, in your Element you would assign this font name to the FontFamily attribute using filename#fontname and just fontname for iOS.
In Flutter, place the font file in a folder and reference it in the pubspec.yaml file, similar to how you import images.
fonts:
- family: MyCustomFont
fonts:
- asset: fonts/MyCustomFont.ttf
- style: italic
Then assign the font to your Text widget:
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Sample App"),
),
body: new Center(
child: new Text(
'This is a custom font text',
style: new TextStyle(fontFamily: 'MyCustomFont'),
),
),
);
}
How do I style my text widgets?
Along with fonts, you can customize other styling elements on a Text widget. The style parameter of a Text widget takes a TextStyle object, where you can customize many parameters, such as:
-
color -
decoration -
decorationColor -
decorationStyle -
fontFamily -
fontSize -
fontStyle -
fontWeight -
hashCode -
height -
inherit -
letterSpacing -
textBaseline -
wordSpacing
Semantic portal