修复单选商品复制问题

hmxc
张萌 4 years ago
parent 1a5dff9efd
commit 0051648ce4

@ -110,21 +110,22 @@ class CartProvidde with ChangeNotifier {
///
changeCheckState(AkuShopModel cartItem) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
cartString = prefs.getString("cartInfo");
List<Map> tempList = (json.decode(cartString.toString()) as List).cast();
int tempIndex = 0;
int changeIndex = 0;
tempList.forEach((item) {
if (item["itemid"] == cartItem.itemid) {
changeIndex = tempIndex;
}
tempIndex++;
});
tempList[changeIndex] = cartItem.toJson();
cartString = json.encode(tempList).toString();
prefs.setString("cartInfo", cartString);
await getCartInfo();
// SharedPreferences prefs = await SharedPreferences.getInstance();
// cartString = prefs.getString("cartInfo");
// List<Map> tempList = (json.decode(cartString.toString()) as List).cast();
// int tempIndex = 0;
// int changeIndex = 0;
// tempList.forEach((item) {
// if (item["itemid"] == cartItem.itemid) {
// changeIndex = tempIndex;
// }
// tempIndex++;
// });
// tempList[changeIndex] = cartItem.toJson();
// cartString = json.encode(tempList).toString();
// prefs.setString("cartInfo", cartString);
// await getCartInfo();
notifyListeners();
}
///

Loading…
Cancel
Save