简体   繁体   English

如何在 flutter 中设置整个应用程序的背景颜色

[英]how to set whole app background color in flutter

is there a way to set whole app backgorundcolor in flutter. For example i want to use white background on all screens.有没有办法在 flutter 中设置整个应用程序的背景颜色。例如,我想在所有屏幕上使用白色背景。 so the first thing i do is manually setting background color to all screens.所以我做的第一件事就是手动设置所有屏幕的背景颜色。 But i think its overkill.但我认为它矫枉过正。 and i am looking for the a shortcut to achieve it.我正在寻找实现它的捷径。

i have tried below code but couldn't get achieve what i wanted.我试过下面的代码但无法实现我想要的。

  @override
  Widget build(BuildContext context) {
    return BlocProvider<SplashBloc>(
      bloc: splashBloc,
      child: MaterialApp(
        theme: new ThemeData(scaffoldBackgroundColor: Colors.white),
        home: Splash(),
      ),
    );
  }
}

In main.dart, use,在 main.dart 中,使用,

MaterialApp(
theme: ThemeData(
scaffoldBackgroundColor: Colors.white),
),

This will change the background color of the entire app provided you are returning Scaffold in the build Widget.如果您在构建小部件中返回脚手架,这将更改整个应用程序的背景颜色。

You use use the theme in your MaterialApp Widget to set up the theme colors for your entire app like so:您可以在 MaterialApp 小部件中使用主题来为整个应用设置主题 colors,如下所示:

MaterialApp(
        theme: ThemeData(
          primaryIconTheme: IconThemeData(color: Colors.white),
          primaryColor: Color.fromRGBO(254, 248, 248, 1),
          appBarTheme: AppBarTheme(
            color: <color_of_choice>,
          ),
        ),

Your backgroundColor will assume the primaryColor above.您的 backgroundColor 将采用上面的 primaryColor。

Read all about it here . 在这里阅读所有相关信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM