app_check_box.dart 1.3 KB

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