circle_check_box.dart 1.8 KB

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