如何在ThemeData
内全局设置行高?
theme: ThemeData(
brightness: Brightness.light,
accentColor: myAccentColor,
primaryColor: myPrimaryColor,
fontFamily: 'Ubuntu',
buttonTheme: ThemeData.light().buttonTheme.copyWith(
buttonColor: myPrimaryColor,
textTheme: ButtonTextTheme.primary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)),
),
scaffoldBackgroundColor: myBackgroundWhite,
cardColor: myBackgroundWhite,
textSelectionColor: myGreyTextColor,
cursorColor: myAccentColor,
cupertinoOverrideTheme: CupertinoThemeData(
primaryColor: myAccentColor,
),
errorColor: myErrorColorRed,
)
答案 0 :(得分:2)
我们不能直接从line-height
设置height
(商品名称:ThemeData
)。
处理文本样式的最佳实践是使用材料类型系统准则。请参见here.
中的“材料文字比例:现代化Flutter文字主题”部分因此,然后在全局ThemeData
上,您可以使用
theme: ThemeData(
brightness: Brightness.light,
accentColor: flujoAccentColor,
primaryColor: flujoPrimaryColor,
fontFamily: 'FiraSans',
textTheme: TextTheme(
headline5: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w700,
fontStyle: FontStyle.normal,
),
bodyText1: TextStyle(
fontSize: 16.0,
fontStyle: FontStyle.normal,
letterSpacing: 0.5,
),
bodyText2: TextStyle(
fontSize: 14.0,
fontStyle: FontStyle.normal,
letterSpacing: 0.25,
height: 1.5,
),
subtitle1: TextStyle(
fontSize: 16.0,
fontStyle: FontStyle.normal,
letterSpacing: 0.15,
),
subtitle2: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
caption: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
overline: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
letterSpacing: 0.25,
height: 1.5,
fontStyle: FontStyle.normal,
)),
像这样,在Text
小部件上,像这样应用它:
Text(
"Hello world!",
style: Theme.of(context).textTheme.bodyText1.copyWith(color: Colors.teal,),
);