round_check_box.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import 'package:flutter/material.dart';
  2. class RoundCheckBox extends StatefulWidget {
  3. final bool value;
  4. final double size;
  5. final Color activeColor;
  6. final Color defaultColor;
  7. final Function(bool) onChanged;
  8. RoundCheckBox({Key key, this.value = false, this.onChanged, this.size,
  9. this.activeColor = Colors.white, this.defaultColor = Colors.white }) : super(key: key);
  10. @override
  11. _RoundCheckBoxState createState() => _RoundCheckBoxState();
  12. }
  13. class _RoundCheckBoxState extends State<RoundCheckBox> {
  14. bool value = false;
  15. _RoundCheckBoxState() {
  16. value = widget.value;
  17. }
  18. @override
  19. Widget build(BuildContext context) {
  20. return Center(
  21. child: GestureDetector(
  22. onTap: () {
  23. value = !value;
  24. widget.onChanged(value);
  25. },
  26. child: Padding(
  27. padding: const EdgeInsets.all(10.0),
  28. child: widget.value ? Icon(
  29. Icons.check_circle,
  30. size: widget.size,
  31. color: widget.activeColor,
  32. ) : Icon(
  33. Icons.panorama_fish_eye,
  34. size: widget.size,
  35. color: widget.defaultColor,
  36. ),
  37. )),
  38. );
  39. }
  40. }