You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.4KB

  1. import 'package:flutter/material.dart';
  2. import '../../../themes/app_dimension.dart';
  3. import '../../../themes/app_colors.dart';
  4. import '../../../themes/styles_text.dart';
  5. class CheckboxWidget extends StatefulWidget {
  6. final String title;
  7. final bool isChecked;
  8. final Function(bool) onChange;
  9. final TextStyle? style;
  10. const CheckboxWidget({
  11. Key? key,
  12. required this.title,
  13. required this.isChecked,
  14. required this.onChange,
  15. this.style,
  16. }) : super(key: key);
  17. @override
  18. _CheckboxWidgetState createState() => _CheckboxWidgetState();
  19. }
  20. class _CheckboxWidgetState extends State<CheckboxWidget> {
  21. var checked = false;
  22. @override
  23. void initState() {
  24. super.initState();
  25. checked = widget.isChecked;
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return InkWell(
  30. onTap: () {
  31. setState(() {
  32. checked = !checked;
  33. widget.onChange(checked);
  34. });
  35. },
  36. child: Row(
  37. children: [
  38. checked
  39. ? Icon(
  40. Icons.check_box,
  41. color: AppColors.primary1,
  42. )
  43. : Icon(
  44. Icons.check_box_outline_blank,
  45. color: AppColors.neutral1,
  46. ),
  47. SizedBox(
  48. width: 8.w,
  49. ),
  50. Text(
  51. '${widget.title}',
  52. style: widget.style ?? StylesText.body1,
  53. ),
  54. ],
  55. ),
  56. );
  57. }
  58. }