12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import 'package:flutter/material.dart';
- import 'package:lszlgl/base/base_lifecycle_state.dart';
- class PrintCheckboxWidget extends StatefulWidget {
- final num itemId;
- final ValueChanged<bool> onChanged;
- final List<num> list;
- const PrintCheckboxWidget({
- super.key,
- required this.itemId,
- required this.list,
- required this.onChanged,
- });
- @override
- State<PrintCheckboxWidget> createState() => _PrintCheckboxWidgetState();
- }
- class _PrintCheckboxWidgetState extends State<PrintCheckboxWidget> {
- 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,
- ),
- );
- }
- }
|