功能: 1.实现了listview局部刷新。 2.checkbox状态保存 item:关键代码 Container( child: MyCheckBox(index, selectState), width: 30, height: 30, padding: EdgeInsets.all(5), ),

class MyCheckBox extends StatefulWidget {
//位置
int index;

//保存所有状态的map
Map myMap;

MyCheckBox(this.index, this.myMap);

@override
State<StatefulWidget> createState() {
// TODO: implement createState
return MyCheckBoxState();
}
}

class MyCheckBoxState extends State<MyCheckBox> {
@override
Widget build(BuildContext context) {
// TODO: implement build

return GestureDetector(
child: widget.myMap[widget.index]
? Image.asset('images/icon_checkbox_checked.png')
: Image.asset('images/icon_checkbox_normal.png'),
onTap: () {
widget.myMap[widget.index] = !widget.myMap[widget.index];
setState(() {});
},
);
}
}

flutter-listview局部刷新。listview带有checkbox_状态保存

flutter-listview局部刷新。listview带有checkbox_ico_02