您可以在 constants.dart 文件中定义一个 const DEF_TEXT_STYLE,然后在需要时应用它。
constants.dart
const DEF_TEXT_STYLE = const TextStyle(
letterSpacing: 1.0);
你可以这样申请:
Text(
'This is my text',
style: DEF_TEXT_STYLE,
),
记得导入你的 constants.dart 文件。
否则,您可以覆盖所有 textTheme 数据,类似于 @glavigno 所说的:
在这里你可以看到 Flutter 中所有可用的 textTheme 数据。
DOCS
theme: ThemeData(
textTheme: TextTheme(
headline1: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
headline2: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
headline3: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
headline4: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
headline5: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
headline6: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
subtitle1: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
subtitle2: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
bodyText1: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
bodyText2: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
button: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
caption: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
overline: Theme.of(context)
.textTheme
.headline1
.copyWith(letterSpacing: 1.0),
),
),