给个字体下载的地址:http://www.diyiziti.com/Download/308
fonts:
- family: MaoTi # 字体别名
fonts:
- asset: fonts/mao_ti.ttf # 字体文件目录
weight: 700 # 权重 700表示粗体,相当于bold
- family: PingFang
fonts:
- asset: fonts/ping_fang.ttf
MaterialApp(
theme: ThemeData(
fontFamily: "PingFang", // 统一指定应用的字体。
primarySwatch: Colors.green,
primaryColor: Colors.white),
。。。
TextStyle(
fontFamily:"PingFang", // 指定该Text的字体。
fontSize: SizeUtil.getFontSize(Dimens.font_sp12),
color: CustomColors.colorPrimary,
fontWeight: FontWeight.bold)
var textFontStyle = TextStyle(
fontFamily:"PingFang", // 指定该Text的字体。
)
用到的地方用 .copyWith 这个方法, 如:
Text(
"显示我想要的字体",
style: textFontStyle.copyWith(
fontSize: 18.0,
color: Colors.red,
fontWeight: FontWeight.bold,
),
)
TextStyle的copyWith如下:
TextStyle copyWith({
bool inherit,
Color color,
Color backgroundColor,
String fontFamily,
List fontFamilyFallback,
double fontSize,
FontWeight fontWeight,
FontStyle fontStyle,
double letterSpacing,
double wordSpacing,
TextBaseline textBaseline,
double height,
Locale locale,
Paint foreground,
Paint background,
List shadows,
TextDecoration decoration,
Color decorationColor,
TextDecorationStyle decorationStyle,
double decorationThickness,
String debugLabel,
})