Flutter - how to change radio background color
Asked Answered
A

2

0

Flutter Radio background is transparent by default, is it possible to change it?

enter image description here

I can wrap with container and set background container color. However, the radio has a padding for hover color, so there is a padding between container background and radio button. I can hardcode container size but it is not good solution.

Container(
              width: 20,
              height: 20,
              decoration: BoxDecoration(color: Colors.orange, shape: BoxShape.circle),
              child: Theme(
                  data: Theme.of(context).copyWith(
                      unselectedWidgetColor: Colors.white
                  ),
                  child: Radio(
                      value: gender,
                      activeColor: Colors.white,
                      groupValue: _gender,
                      onChanged: (Gender value) {
                        setState(() {
                          _gender = value;
                        });
                      }))),
Abrahan answered 2/10, 2020 at 5:5 Comment(2)
Did you figure it out? Same issue, no answers here work.Ramp
It seems you have to create a custom controlRamp
J
1
Theme(
  data: Theme.of(context).copyWith(
    unselectedWidgetColor: Colors.red,
    disabledColor: Colors.blue
  ),
  Radio(
                      value: gender,
                      activeColor: Colors.white,
                      groupValue: _gender,
                      onChanged: (Gender value) {
                        setState(() {
                          _gender = value;
                        });
                      }),
)

you have to give disabledColor

Junia answered 2/10, 2020 at 6:33 Comment(2)
Thanks for your answer, but it doesn't work. I want to change background of both selected and unselected radio buttonsAbrahan
I guess disabledColor is doing for youJunia
M
0
Theme(
       data: ThemeData(
       toggleableActiveColor: Colors.red,
       unselectedWidgetColor: Colors.grey),
     child: Radio(`enter code here)
Mcnair answered 14/3, 2022 at 7:6 Comment(1)
See "Explaining entirely code-based answers". While this might be technically correct, it doesn't explain why it solves the problem or should be the selected answer. We should educate along with helping solve the problem.Foreclose

© 2022 - 2024 — McMap. All rights reserved.