birzha_mobile/lib/components/radio.dart

96 lines
2.3 KiB
Dart
Raw Permalink Normal View History

2023-02-27 07:23:37 +00:00
import 'package:flutter/material.dart';
class RadioItem<T>{
late final String name;
late final T value;
late final T groupValue;
RadioItem({required this.name,required this.value,required this.groupValue});
}
///Widget that draw a beautiful checkbox rounded. Provided with animation if wanted
class RadioButton extends StatefulWidget {
const RadioButton({
Key? key,
required this.checkedColor,
required this.uncheckedColor,
required this.value,
required this.onChange,
required this.borderColor,
required this.size,
required this.borderWidth,
required this.animationDuration,
required this.groupValue,
}) :
super(key: key);
//Define borderWidth
final double borderWidth;
///Define the color that is shown when Widgets is checked
final Color checkedColor;
///Define the color that is shown when Widgets is unchecked
final Color uncheckedColor;
///Define the border of the widget
final Color borderColor;
///Define the size of the checkbox
final double size;
///Define the duration of the animation. If any
final Duration animationDuration;
// value of item
final dynamic value;
// onchange of value
final Function(dynamic) onChange;
//groupValue of radios
final dynamic groupValue;
@override
_RadioButtonState createState() => _RadioButtonState();
}
class _RadioButtonState extends State<RadioButton> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
widget.onChange(widget.value);
},
child: ClipRRect(
borderRadius: BorderRadius.circular(widget.size / 2),
child: AnimatedContainer(
duration: widget.animationDuration,
height: widget.size,
width: widget.size,
decoration: BoxDecoration(
color: widget.value == widget.groupValue ? widget.checkedColor : widget.uncheckedColor,
border: Border.all(
color: widget.value == widget.groupValue? widget.checkedColor: widget.borderColor,
width: widget.borderWidth
),
borderRadius: BorderRadius.circular(widget.size / 2),
),
child: Container()
),
),
);
}
}