Key takeaways:
The fontWeight
property in TextStyle
provides granular control over text weight, with options ranging from FontWeight.w100
(Ultra Light) to FontWeight.w900
(Black). The default is FontWeight.w400
(Regular).
The RichText
widget combines with TextSpan
to apply bold styling to specific parts of a text string, enabling dynamic and flexible text formatting.
Flutter supports custom fonts through the fontFamily
property, offering developers the ability to load and style text with personalized fonts while maintaining compatibility with fontWeight
.
We can combine different font weights (w100
, w500
, w700
, etc.) within the same UI to create visually distinct and appealing typography, suited for headers, labels, or content emphasis.
In Flutter, text styling is crucial to creating visually appealing user interfaces. Making text bold is a common requirement when emphasizing certain parts of our app’s content. Fortunately, Flutter provides a straightforward and flexible way to achieve this. This Answer will explore different methods of bold text in Flutter and provide code examples for each approach.
Method 1: Using Flutter font weights
To make text bold in Flutter, we can use the fontWeight
property of the TextStyle
class. The fontWeight
property takes a value from the FontWeight
enum, which ranges from 100 to 900. The higher the value, the bolder the font will appear.
Here is a list of the available font weights and their corresponding descriptions:
Default Flutter text weights
If we omit the fontWeight
property, the default value (FontWeight.w400
) will be used, and the text will be displayed in the normal weight of the default font as shown below: