Clearing shopping cart
This commit is contained in:
@@ -151,6 +151,23 @@ class _BasketPageState extends State<BasketPage> {
|
|||||||
),
|
),
|
||||||
child: const Text('Оформить заказ'),
|
child: const Text('Оформить заказ'),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await clearCart();
|
||||||
|
setState(() {
|
||||||
|
cartItems = [];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.all(Radius.circular(50))),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
),
|
||||||
|
child: const Text('Очистить корзину'),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -40,3 +40,8 @@ Future<void> removeItemFromCart(String id) async {
|
|||||||
}
|
}
|
||||||
prefs.setString('cart', jsonEncode(cart));
|
prefs.setString('cart', jsonEncode(cart));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> clearCart() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
prefs.setString('cart', "[]");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user