app_check_box.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'package:flutter/material.dart';
  2. import 'package:ftrecruiter/comm/widget/common_widget.dart';
  3. //CheckBox控件封装
  4. class AppCheckbox extends StatefulWidget {
  5. final String? label;
  6. final bool? checked;
  7. final Function(bool?)? onChecked;
  8. AppCheckbox({this.label, this.checked, 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. print(checked);
  16. setState(() {
  17. _checked = checked;
  18. });
  19. if (widget.onChecked != null) {
  20. widget.onChecked!(checked);
  21. }
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. return SafeArea(
  26. child: Row(
  27. crossAxisAlignment: CrossAxisAlignment.start,
  28. children: [
  29. SizedBox(
  30. width: 24.0,
  31. height: 24.0,
  32. child: Checkbox(
  33. value: _checked,
  34. materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  35. onChanged: _onChecked),
  36. ),
  37. CommonWidget.rowWidth(width: 10.0),
  38. Flexible(
  39. child: Text(
  40. widget.label!,
  41. textAlign: TextAlign.left,
  42. style: const TextStyle(
  43. fontSize: 13.0,
  44. color: Colors.white,
  45. ),
  46. ),
  47. ),
  48. ],
  49. ),
  50. );
  51. }
  52. }