如何在Dart中设置动态主题,也可以使用targetplatform.ios

时间:2019-01-20 08:24:01

标签: dart flutter

我正在使用动态主题来快速更改应用程序主题。某些代码的编写方式类似于

theme: theme,

但是我也希望滑动后退,所以我使用

theme: new ThemeData(platform: TargetPlatform.iOS),

现在我要同时使用它们,我应该如何更改代码?

完整代码在这里:

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new DynamicTheme(
        defaultBrightness: Brightness.light,
        data: (brightness) => new ThemeData(
              primarySwatch: Colors.orange,
              brightness: brightness,
            ),
        themedWidgetBuilder: (context, theme) {
          return new MaterialApp(
            home: new HomePage(),
            theme: theme,
            // theme: new ThemeData(
            //     platform: TargetPlatform.iOS),
            routes: <String, WidgetBuilder>{
              '/home': (BuildContext context) => new HomePage(),
              '/search': (BuildContext context) => new SearchPage(),
            },
          );
        });
  }
}

0 个答案:

没有答案