I want to do button like these ones, I tried with radio button but I can't customize them. Do you have any ideas how can I make that ?
I've wrote a re-usable widget which mimic the radio button behaviour:
Custom Radio Widget
class CustomRadioWidget<T> extends StatelessWidget {
final T value;
final T groupValue;
final ValueChanged<T> onChanged;
final double width;
final double height;
CustomRadioWidget({this.value, this.groupValue, this.onChanged, this.width = 32, this.height = 32});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {
onChanged(this.value);
},
child: Container(
height: this.height,
width: this.width,
decoration: ShapeDecoration(
shape: CircleBorder(),
gradient: LinearGradient(
colors: [
Color(0xFF49EF3E),
Color(0xFF06D89A),
],
),
),
child: Center(
child: Container(
height: this.height - 8,
width: this.width - 8,
decoration: ShapeDecoration(
shape: CircleBorder(),
gradient: LinearGradient(
colors: value == groupValue ? [
Color(0xFFE13684),
Color(0xFFFF6EEC),
] : [
Theme.of(context).scaffoldBackgroundColor,
Theme.of(context).scaffoldBackgroundColor,
],
),
),
),
),
),
),
);
}
}
You can add it to your code like:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CustomRadioWidget(
value: "0",
groupValue: _radValue,
onChanged: (String value) {
setState(() {
_radValue = value;
});
},
),
CustomRadioWidget(
value: "1",
groupValue: _radValue,
onChanged: (String value) {
setState(() {
_radValue = value;
});
},
),
],
),
The output looks like this:
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