我的应用程序是使用 aMaterialApp
作为根小部件构建的。在这个材料应用程序中,我添加了一个主题,如下所示:
MaterialApp(
theme: myTheme,
home: MyHomePage(),
...
)
final ThemeData myTheme = _buildTheme();
ThemeData _buildTheme() {
final ThemeData base = ThemeData.light();
return base.copyWith(
...
textTheme: _buildMyTextTheme(base.textTheme),
primaryTextTheme: _buildMyTextTheme(base.primaryTextTheme),
accentTextTheme: _buildMyTextTheme(base.accentTextTheme),
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}));
}
TextTheme _buildMyTextTheme(TextTheme base) {
return base
.copyWith(
headline:
base.headline.copyWith(fontSize: 20.0, fontWeight: FontWeight.w500),
title: base.title.copyWith(fontSize: 18.0, fontWeight: FontWeight.w400),
subhead:
base.subhead.copyWith(fontSize: 16.0, fontWeight: FontWeight.w400),
body1: base.body1.copyWith(fontSize: 14.0, fontWeight: FontWeight.w400),
body2: base.body2.copyWith(fontSize: 14.0, fontWeight: FontWeight.w500),
caption: base.caption.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12.0,
),
)
.apply(
fontFamily: 'myfont',
displayColor: Colors.black,
bodyColor: Colors.black,
);
}
我习惯于Theme.of(context.textTheme
在小部件树下为整个应用程序中的文本设置样式。
例如:我使用的标题
Text('Title', style:Theme.of(context).textTheme.title),
到我用过的字幕
Text('Title', style:Theme.of(context).textTheme.subhead),
它按预期工作。但是现在我想使用一个CupertinoApp
如果当前平台是 ios 因为它提供了本机 ios 感觉
- 项目清单
- 页面将通过向后滑动关闭。滚动过去的四肢将触发 iOS 风格的弹簧过度滚动。
我应该如何添加应用相同文本主题的 CupertionApp?