import 'package:flutter/material.dart'; import 'package:lszlgl/base/base_lifecycle_state.dart'; class PrintCheckboxWidget extends StatefulWidget { final num itemId; final ValueChanged onChanged; final List list; const PrintCheckboxWidget({ super.key, required this.itemId, required this.list, required this.onChanged, }); @override State createState() => _PrintCheckboxWidgetState(); } class _PrintCheckboxWidgetState extends State { bool _select = false; @override void initState() { super.initState(); for(num item in widget.list){ if(item ==widget.itemId){ _select = true; break ; } } } @override Widget build(BuildContext context) { return IconButton( iconSize: 40, padding: const EdgeInsets.all(0), color: Colors.white, onPressed: () { if(!_select && widget.list.length>=5){ MyNavigator.showToast('一次最多选5条数据'); return; } setState(() { _select = !_select; }); widget.onChanged(_select); }, icon: Icon( Icons.check_circle, color: _select ? Colors.green : Colors.grey, ), ); } }