如何在颤振中更改 ThemeData 的“主色”?

Dhi*_*abi 8 flutter

我正在使用 flutter2.8.0创建一个简单的应用程序。但是当我尝试更改应用程序的主颜色时,它对我不起作用。

这是我正在处理的代码:

class BMICalculator extends StatelessWidget {
  const BMICalculator({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        primaryColor: const Color(0xFF0A0E21),
        scaffoldBackgroundColor: const Color(0xFF0A0E21),
      ),
      home: const InputPage(),
    );
  }
}

Run Code Online (Sandbox Code Playgroud)

Mri*_*ain 0

使用主要Swatch

theme: ThemeData(
primarySwatch: Colors.red,
),
Run Code Online (Sandbox Code Playgroud)

  • 这对我有用,但我需要用深色的“ThemeData”来完成。 (2认同)