解决Flutter顶部栏颜色修改 theme: ThemeData(primaryColor: Colors.white)不起作用的问题

解决Flutter顶部栏颜色修改 theme: ThemeData(primaryColor: Colors.white)不起作用的问题

return MaterialApp(
debugShowCheckedModeBanner: false, // home: Tabs(),
initialRoute: '/', onGenerateRoute:onGenerateRoute, 
theme: ThemeData(
primaryColor: Colors.white
), 
)

发现顶部栏颜色没有变化

改成以下代码:

return MaterialApp(
        home: Tabs(),
        debugShowCheckedModeBanner: false,
        initialRoute: '/',
        onGenerateRoute: onGenerateRoute,
        theme: ThemeData(
            colorScheme: const ColorScheme(
                primary: Colors.white, //顶部栏栏颜色
                primaryVariant: Colors.white,
                secondary: Colors.green,
                background: Colors.white,
                error: Colors.red,
                brightness: Brightness.light,
                onBackground: Colors.pink,
                secondaryVariant: Colors.white,
                onError: Colors.yellow,
                onPrimary: Colors.white, //顶部栏字体颜色
                onSecondary: Colors.redAccent,
                onSurface: Colors.redAccent,
                surface: Colors.redAccent
                // all fields should have a value
                )),
      );

ColorScheme中必须的参数较多,每一个都需要填写

如果不想要写所有参数,可以采用以下方式

theme: ThemeData(
        colorScheme: const ColorScheme.light(
            primary: Colors.white,
            onPrimary: Colors.white,
            onBackground: Colors.white,
            secondary: Colors.amber),
      ),

你可能感兴趣的:(Dart,flutter,android)