如何为整个MaterialApp的主题设置背景颜色?

时间:2019-04-04 21:05:30

标签: dart flutter

我正在尝试在Flutter中更改整个MaterialApp主题的背景颜色。 ThemeData的scaffoldBackgroundColor可以工作,但是我不是100%确信Flutter中的MaterialApp应该被编码。

@override
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  final AllText allText = AllText();
  final colorOrange = const Color(0xFFF89921);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      // Tells the system which are the supported languages
      supportedLocales: allTranslations.supportedLocales(),
      title: allText.foreCanvass,
      theme: ThemeData(
        scaffoldBackgroundColor: colorOrange,
      ),

      initialRoute: '/',
      routes: {
        '/': (context) => UserLogin(),
      },
    );
  }
}

1 个答案:

答案 0 :(得分:2)

您所做的已经正确,您应该尝试完全重启。除非进行完全重启或热重启,否则main的更改不会更改。