import 'package:flutter/material.dart'; import 'package:twong/utils/index.dart'; class CircleCheckBox extends StatefulWidget { final Color color; final bool initValue; final Widget child; final double size; final bool right; final Function(bool) onChange; CircleCheckBox(this.onChange, {this.initValue = false, this.right = true, this.color = Colors.red, this.child, this.size = 20 }); @override State createState() { return _CircleCheckBoxState(); } } class _CircleCheckBoxState extends State { bool selected = false; @override Widget build(BuildContext context) { return InkWell( onTap: () { setState(() { selected = !selected; }); widget.onChange(selected); }, child: widget.right ? Row( children: [ widget.child, Container( alignment: Alignment.center, margin: EdgeInsets.only(left: 6.px), child: selected ? Icon(Icons.radio_button_on, size: widget.size, color: widget.color) : Icon( Icons.radio_button_off, size: widget.size, color: widget.color), ) ], ) : Row( children: [ Container( alignment: Alignment.center, margin: EdgeInsets.only(right: 6.px), child: selected ? Icon(Icons.radio_button_on, size: widget.size, color: widget.color) : Icon( Icons.radio_button_off, size: widget.size, color: widget.color), ), widget.child ], ), ); } }