我想为我的 flutter 应用程序使用不同的主题,这取决于它启动的操作系统。
Theme.of(context).platform == TargetPlatform.iOS
不起作用,因为我还没有应用主题...
您可以通过将视图包装到具有自定义属性的新Theme
实例中来轻松覆盖主题。
您可以执行以下操作:
return new MaterialApp(
// default theme here
theme: new ThemeData(),
builder: (context, child) {
final defaultTheme = Theme.of(context);
if (defaultTheme.platform == TargetPlatform.iOS) {
return new Theme(
data: defaultTheme.copyWith(
primaryColor: Colors.purple
),
child: child,
);
}
return child;
}
);
这将指定一个默认主题。然后覆盖 IOS 的primaryColor
。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(78条)