我的应用是使用MaterialApp
作为根窗口小部件而构建的。在此材料应用程序中,我添加了一个主题,如下所示:
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),
它按预期工作。
但是,如果当前平台是ios,那么我想使用CupertinoApp
,因为它提供了原生ios的感觉
如何使用相同的文本主题添加CupertionApp?
答案 0 :(得分:1)
您可以使用auto myints = torch::Tensor({10, 20, 30, 40, 50, 60, 70});
auto myvector = torch::ones({18});
myvector.slice(0, 4, 7) = myints.slice(0,0,3);
小部件包装CupertinoApp
:
Theme