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

问题描述 投票:0回答:1

我正在尝试在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(),
      },
    );
  }
}
dart flutter
1个回答
2
投票

你在做什么已经是正确的,你应该尝试完全重启。除非您执行完全重启或热重启,否则主要更改不会更改。

© www.soinside.com 2019 - 2024. All rights reserved.