// 我正在尝试这段代码,但它没有添加到 firebase
void checkItemInCart(String shortInfoAsId, BuildContext context) {
EcommerceApp.sharedPreferences
.getString(EcommerceApp.userCartList)
.contains(shortInfoAsId)
? Fluttertoast.showToast(msg: "Item already in Cart.")
: addItemToCart(shortInfoAsId, context);
}
addItemToCart(String shortInfoAsId, BuildContext context) {
List tempCartList =
EcommerceApp.sharedPreferences.getStringList(EcommerceApp.userCartList);
tempCartList.add(shortInfoAsId);
EcommerceApp.firestore.collection(EcommerceApp.collectionUser)
.document(EcommerceApp.sharedPreferences.getString(EcommerceApp.userUID))
.updateData({
EcommerceApp.userCartList: tempCartList,
}).then((v){
Fluttertoast.showToast(msg: "Item Added to Cart Successfully");
EcommerceApp.sharedPreferences.setStringList(EcommerceApp.userCartList,
tempCartList);
Provider.of<CartItemCounter>(context, listen: false).displayResult();
});
}
// 它给出了这些错误
处理手势时引发以下 _TypeError:类型“列表”不是“字符串”类型的子类型
抛出异常时,这是堆栈:#0 SharedPreferences.getString (package:shared_preferences/shared_preferences.dart:98:35) #1 checkItemInCart (package:e_shop/Store/storehome.dart:331:12) #2 sourceInfo . (包:e_shop/Store/storehome.dart:301:31)#3 _InkResponseState._handleTap(包:flutter/src/material/ink_well.dart:993:19)#4 _InkResponseState.build。(包:flutter/src/material/ink_well.dart:1111:38)...处理程序:“onTap”识别器:TapGestureRecognizer#47ccb debugOwner:GestureDetector 状态:准备好赢得竞技场finalPosition:Offset(380.3,334.6)finalLocalPosition:Offset( 22.8, 31.6) 按钮:1 发送点击向下