circle_check_box.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'package:flutter/material.dart';
  2. import 'package:twong/utils/index.dart';
  3. class CircleCheckBox extends StatefulWidget {
  4. final Color color;
  5. final bool initValue;
  6. final Widget child;
  7. final double size;
  8. final bool right;
  9. final Function(bool) onChange;
  10. CircleCheckBox(this.onChange, {this.initValue = false, this.right = true,
  11. this.color = Colors.red, this.child, this.size = 20 });
  12. @override
  13. State<StatefulWidget> createState() {
  14. return _CircleCheckBoxState();
  15. }
  16. }
  17. class _CircleCheckBoxState extends State<CircleCheckBox> {
  18. bool selected = false;
  19. @override
  20. Widget build(BuildContext context) {
  21. return InkWell(
  22. onTap: () {
  23. setState(() {
  24. selected = !selected;
  25. });
  26. widget.onChange(selected);
  27. },
  28. child: widget.right ? Row(
  29. children: [
  30. widget.child,
  31. Container(
  32. alignment: Alignment.center,
  33. margin: EdgeInsets.only(left: 6.px),
  34. child: selected ? Icon(Icons.radio_button_on, size:
  35. widget.size, color: widget.color) : Icon(
  36. Icons.radio_button_off, size: widget.size, color: widget.color),
  37. )
  38. ],
  39. ) : Row(
  40. children: [
  41. Container(
  42. alignment: Alignment.center,
  43. margin: EdgeInsets.only(right: 6.px),
  44. child: selected ? Icon(Icons.radio_button_on, size:
  45. widget.size, color: widget.color) : Icon(
  46. Icons.radio_button_off, size: widget.size, color: widget.color),
  47. ),
  48. widget.child
  49. ],
  50. ),
  51. );
  52. }
  53. }