[英]Setting color of the button through theme in Flutter
我希望在 flutter 中开发的应用程序中的所有按钮颜色相同。 我试图通过 **ThemeData(ButtonThemeData) 设置它,但什么也没有。
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.dark,
primarySwatch: Colors.blue,
primaryColor: Colors.lightBlue[800],
accentColor: Colors.orange,
buttonTheme: ButtonThemeData(
buttonColor: Colors.blue,
),
),
我的按钮代码是
Padding(
padding: const EdgeInsets.all(8),
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
side: BorderSide(color: Colors.white),
),
child: Text("Take Quiz"),
),
),
这应该工作
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.dark,
primarySwatch: Colors.blue,
primaryColor: Colors.lightBlue[800],
accentColor: Colors.orange,
buttonColor: Colors.blue, //this line here
),
我知道了。 其实问题出在
ThemeData.dark()
这是一个预定义的主题。 如果你想改变其中的任何东西,你必须使用
ThemeData.dark().copywith(//here you will define your scheme)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.