What I Currently Have
What I want to achieve
The Code that I have now
Radio(
value: 2,
groupValue: val,
onChanged: (value) {
setState(() {
val = value;
});
},
activeColor: secondaryColor,)
Since the radio button contains a label, we can't use the Radio button. Instead, we are going to create a custom class that can be used the create the options called MyRadioOption . Inspired by Flutter's Radio widget, the class has value , groupValue , and onChanged properties.
ListTile( onTap: () => onChanged(template.id), leading: Radio( value: template.id, groupValue: checkedId, ) ... ) Doing that, the Radio becomes "inactive" and changes it's color to grey. The Radio has an activeColor property, but not for inactive.
We can change the border color using BorderSide class. to Change Border Color of ElevatedButton in Flutter ElevatedButton has style Property so we can use the styleFrom method should be used to change the default style of the elevated button. We can change the border color using BorderSide class.
To change the border color of the radio button when it is unselected just wrap the radio button inside a Theme widget as a child and set ThemeData ‘s unselectedWidgetColor property to your desired color. That brings an end to flutter radio button example tutorial.
In this example tutorial, we will learn how to use a radio button widget in flutter and its properties with examples. Radio button in flutter is nothing but an option button where the user can select only one option from a group of options. The selected state is nothing but ON and unselected is OFF.
Border widget in flutter is assigned a simple functionality to add borders to the other widgets. The first is by creating all borders using BorderSide. The second way is by using Border.all to create a uniform border having the same color and width. The third is by using Border.fromBorderSide to create a border whose sides are all same.
Flutter – Change Container Border’s Color & Width. You can change the color and width of Container widget’s border. To change the color and width of Container’s border, use its decoration property. Set decoration property with BoxDecoration () object. Set the border property of BoxDecoration () object, with required color and width as per your ...
It's not possible to customize that much the Radio button. The only color parameter for the button is fillColor. It will impact both the inner plain circle and the outer circle.
If you really want a custom look you'll need to build your own widget. Here is a simple example that you can customize and improve. You could also try to start from the source code of the flutter Radio widget.
class CustomRadio extends StatefulWidget {
final int value;
final int groupValue;
final void Function(int) onChanged;
const CustomRadio({Key? key, required this.value, required this.groupValue, required this.onChanged})
: super(key: key);
@override
_CustomRadioState createState() => _CustomRadioState();
}
class _CustomRadioState extends State<CustomRadio> {
@override
Widget build(BuildContext context) {
bool selected = (widget.value == widget.groupValue);
return InkWell(
onTap: () => widget.onChanged(widget.value),
child: Container(
margin: const EdgeInsets.all(4),
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(shape: BoxShape.circle, color: selected ? Colors.white : Colors.grey[200]),
child: Icon(
Icons.circle,
size: 30,
color: selected ? Colors.deepPurple : Colors.grey[200],
),
),
);
}
}
Result :
There is no way to provide the color of the outer circle in the material Radio class, what you can do is to create your own radio Button, either from scratch (Check the @Tanguy answer)or you copy the Radio class and change its design/behavior. If you decide to copy the Radio class you need to inherit from the Radio so it can work with the rest of the Material design elements. Here is a copy of it https://gist.github.com/karimkod/8f7c93da798670c8b6e9b85ff9fb5383 You can change the paint method of The _RadioPainter class to draw basically whatever you want. I have changed it in the gist to look purple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With