print_checkbox_widget.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:flutter/material.dart';
  2. import 'package:lszlgl/base/base_lifecycle_state.dart';
  3. class PrintCheckboxWidget extends StatefulWidget {
  4. final num itemId;
  5. final ValueChanged<bool> onChanged;
  6. final List<num> list;
  7. const PrintCheckboxWidget({
  8. super.key,
  9. required this.itemId,
  10. required this.list,
  11. required this.onChanged,
  12. });
  13. @override
  14. State<PrintCheckboxWidget> createState() => _PrintCheckboxWidgetState();
  15. }
  16. class _PrintCheckboxWidgetState extends State<PrintCheckboxWidget> {
  17. bool _select = false;
  18. @override
  19. void initState() {
  20. super.initState();
  21. for(num item in widget.list){
  22. if(item ==widget.itemId){
  23. _select = true;
  24. break ;
  25. }
  26. }
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return IconButton(
  31. iconSize: 40,
  32. padding: const EdgeInsets.all(0),
  33. color: Colors.white,
  34. onPressed: () {
  35. if(!_select && widget.list.length>=5){
  36. MyNavigator.showToast('一次最多选5条数据');
  37. return;
  38. }
  39. setState(() {
  40. _select = !_select;
  41. });
  42. widget.onChanged(_select);
  43. },
  44. icon: Icon(
  45. Icons.check_circle,
  46. color: _select ? Colors.green : Colors.grey,
  47. ),
  48. );
  49. }
  50. }