修复单选商品复制问题

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

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

Loading…
Cancel
Save