I have Listview with ListTile populated from db, i have checkbox on each tile and im saving item temporaly in sharepref, so far all good.
The problem is when i query and sort items in diferent order, checkbox save still the same order like in db not in the listview, im guessing i need index-id of an item. So how to get id from db of item in listview?
Widget getListView() {
return Expanded(
child: ListView.builder(
itemCount: _items.length,
shrinkWrap: true,
itemBuilder: (context, index) {
final item = _items[index];
if (item is HeaderItem) {
return Column(
children: <Widget>[
Card(
color: Colors.white,
child: Text(
item.heading,
style: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.w600,
color: Constants.title_header),
),
),
Divider(),
],
);
} else if (item is MessageItem) {
return ListTile(
dense: true,
leading: Checkbox(
value: item.checked,
onChanged: (bool value) {
setState(() {
item.checked = value;
if (value) {
_removeAnswer(_index);
_saveAnswer(_index); //saving to sharePref..
if (_list[7] == "1") {
_removeAnswer2(_index);
_saveAnswerSummary(_index);
}
_index++;
}
if (value == false) {
_index--;
_removeAnswer(_index);
_removeAnswer2(_index);
setState(() {
});
}
print("Check box2: $value");
setState(() {
_getFromDB0(_index);
});
});
},
),
title: Text(
item.title,
),
// subtitle: Text(_list2[index]),
);
}
},
),
);
}
Aucun commentaire:
Enregistrer un commentaire