当我有2个单选按钮,其中一个被选中而另一个未被选中时,其中一个是活动颜色,而另一个是灰色,那么有没有办法将未选择的颜色从灰色变为白色?
当然,你必须改变单选按钮容器的ThemeData
。
假设您使用的是Row
容器:
Theme(
data: ThemeData.dark(), //set the dark theme or write your own theme
child: Row(
children: <Widget>[
Radio(
//your attributes here...
),
Radio(
//your attributes here...
)
],
),
)
这个怎么运作?
因为如果你检查ThemeData
的代码,你会看到这个验证
unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54;
然后黑暗的主题是使用white70
在unselectedWidgetColor
中设置MaterialApp
主题道具,如下所示:
return new MaterialApp(
title: 'xyz',
home: xyz(),
theme: ThemeData(
brightness: Brightness.dark,
unselectedWidgetColor:Colors.white
),
);
一个有用的技巧,阅读radio.dart的源代码,你会得到一切!