Added tODO

This commit is contained in:
2024-05-03 16:00:49 +03:00
parent 4bbe7fbc0b
commit e4628e977f

View File

@@ -42,6 +42,7 @@ List<Map<String, dynamic>> cart = [
}
];
//TODO: Сделать правильное удаление из корзины по одному
class BasketPage extends StatefulWidget {
const BasketPage({super.key});
@@ -63,7 +64,6 @@ class _BasketPageState extends State<BasketPage> {
.toList();
totalPrice =
cartItems.fold(0, (sum, item) => sum + int.parse(item['price']));
debugPrint(totalPrice.toString());
});
});
}
@@ -77,6 +77,77 @@ class _BasketPageState extends State<BasketPage> {
await removeItemFromCart(id);
}
Future<void> _deleteItemAlert(String id, String name) async {
return showDialog<void>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Удаление из корзины'),
content: SingleChildScrollView(
child: ListBody(
children: [
Text('Вы действительно хотите убрать "$name" из корзины?'),
],
),
),
actions: [
TextButton(
child: const Text('Отмена'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: const Text('Удалить'),
onPressed: () {
removeItem(id);
Navigator.of(context).pop();
},
),
],
);
},
);
}
Future<void> _clearCartAlert() async {
return showDialog<void>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Очистка корзины'),
content: const SingleChildScrollView(
child: ListBody(
children: [
Text('Вы действительно хотите очистить корзину?'),
],
),
),
actions: [
TextButton(
child: const Text('Отмена'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: const Text('Очистить'),
onPressed: () {
clearCart();
setState(() {
cartItems = [];
});
Navigator.of(context).pop();
},
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -125,7 +196,8 @@ class _BasketPageState extends State<BasketPage> {
item['image'],
width: 50,
),
onTap: () => removeItem(item['id']),
onTap: () =>
_deleteItemAlert(item['id'], item['name']),
);
},
),
@@ -153,12 +225,7 @@ class _BasketPageState extends State<BasketPage> {
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () async {
await clearCart();
setState(() {
cartItems = [];
});
},
onPressed: _clearCartAlert,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder(