boo*_*boy 2 themes widget ios flutter flutter-cupertino
我的应用程序是使用 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,
);
}
Run Code Online (Sandbox Code Playgroud)
我曾经Theme.of(context.textTheme在整个应用程序中设置小部件树中的文本样式。
例如:我使用的标题
Text('Title', style:Theme.of(context).textTheme.title),
Run Code Online (Sandbox Code Playgroud)
我使用的副标题
Text('Title', style:Theme.of(context).textTheme.subhead),
Run Code Online (Sandbox Code Playgroud)
它按预期工作。但是现在我想使用一个CupertinoApp如果当前平台是 ios 因为它提供了原生 ios 感觉就像
我应该如何添加应用相同文本主题的 CupertionApp?
你可以CupertinoApp用Theme小部件包装:
Theme(
data: yourThemeData(), //your theme data here
child: CupertinoApp(...),
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2372 次 |
| 最近记录: |