flutter 我的应用程序的颜色主题没有改变

uinbv5nw  于 2023-06-07  发布在  Flutter
关注(0)|答案(1)|浏览(200)

我正在学习如何使用Dart编写代码来制作应用程序,当我想将应用程序的颜色主题更改为不同的颜色时,它保持不变。

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: ' My first app',
      theme: ThemeData(primaryColor: Colors.orange),
      home: MyHomePage(),
    );
  }
}
afdcj2ne

afdcj2ne1#

使用ThemeDataprimarySwatch属性更改应用配色方案。使用primaryColor,您只需更改一个值,并且小部件使用不同的颜色阴影。

示例:

final primaryColor=const Color(0xFFa671da);
final primaryColorPalette=const {
 50:Color.fromRGBO(166, 113, 218, .1),
 100:Color.fromRGBO(166, 113, 218, .2),
 200:Color.fromRGBO(166, 113, 218, .3),
 300:Color.fromRGBO(166, 113, 218, .4),
 400:Color.fromRGBO(166, 113, 218, .5),
 500:Color.fromRGBO(166, 113, 218, .6),
 600:Color.fromRGBO(166, 113, 218, .7),
 700:Color.fromRGBO(166, 113, 218, .8),
 800:Color.fromRGBO(166, 113, 218, .9),
 900:Color.fromRGBO(166, 113, 218, 1),
};

...

primarySwatch: MaterialColor(primaryColor.value,primaryColorPalette),

相关问题