颤振中的单选按钮未选择的颜色

问题描述 投票:2回答:2

当我有2个单选按钮,其中一个被选中而另一个未被选中时,其中一个是活动颜色,而另一个是灰色,那么有没有办法将未选择的颜色从灰色变为白色?

flutter
2个回答
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


1
投票

unselectedWidgetColor中设置MaterialApp主题道具,如下所示:

return new MaterialApp(
      title: 'xyz',
      home: xyz(),
      theme: ThemeData(
        brightness: Brightness.dark,
        unselectedWidgetColor:Colors.white
      ),
    );

一个有用的技巧,阅读radio.dart的源代码,你会得到一切!

© www.soinside.com 2019 - 2024. All rights reserved.