app_check_box.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:flutter/material.dart';
  2. //CheckBox控件封装
  3. class AppCheckbox extends StatefulWidget {
  4. final String? label;
  5. final bool? checked;
  6. final Function(bool?)? onChecked;
  7. AppCheckbox({this.label, this.checked, this.onChecked});
  8. @override
  9. _AppCheckboxState createState() => _AppCheckboxState();
  10. }
  11. class _AppCheckboxState extends State<AppCheckbox> {
  12. bool? _checked = false;
  13. void _onChecked(bool? checked) {
  14. setState(() {
  15. _checked = checked;
  16. });
  17. if (widget.onChecked != null) {
  18. widget.onChecked!(checked);
  19. }
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return SafeArea(
  24. child: Row(
  25. crossAxisAlignment: CrossAxisAlignment.start,
  26. children: [
  27. SizedBox(
  28. width: 24.0,
  29. height: 24.0,
  30. child: Checkbox(value: _checked, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onChanged: _onChecked),
  31. ),
  32. SizedBox(width: 10),
  33. Flexible(
  34. child: Text(
  35. widget.label!,
  36. textAlign: TextAlign.left,
  37. style: const TextStyle(
  38. fontSize: 13.0,
  39. color: Colors.white,
  40. ),
  41. ),
  42. ),
  43. ],
  44. ),
  45. );
  46. }
  47. }