【发布时间】:2020-05-30 19:47:49
【问题描述】:
在这里,我想从我的购物车中删除特定产品。我的购物车是使用共享偏好数据生成的。所以基本上我想从共享偏好中删除特定索引。 希望你明白这个问题。我也在这里使用 listview builder 来显示数据。
这是共享偏好的代码,
SharedPreferences preferences = await SharedPreferences.getInstance();
List<String> cartitems = preferences.getStringList('cartItems');
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: unauthCartItems.length,
itemBuilder: (context, index) {
print(unauthCartItems.length);
return FlatButton(
onPressed: () {
//Here i want to clear the Preferences based on index
},
);
},
);
【问题讨论】:
-
您保存了共享首选项,对吗?因此您必须已经知道每个值的键,然后使用该键来更新值。
-
是的,我已经只想从共享首选项中删除这些键值。但我怎么不知道。你能帮忙吗
-
显示你的列表的价值和你想删除的项目
标签: flutter dart sharedpreferences flutter-layout