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 { class BasketPage extends StatefulWidget {
const BasketPage({super.key}); const BasketPage({super.key});
@@ -63,7 +64,6 @@ class _BasketPageState extends State<BasketPage> {
.toList(); .toList();
totalPrice = totalPrice =
cartItems.fold(0, (sum, item) => sum + int.parse(item['price'])); 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); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@@ -125,7 +196,8 @@ class _BasketPageState extends State<BasketPage> {
item['image'], item['image'],
width: 50, 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), const SizedBox(height: 10),
ElevatedButton( ElevatedButton(
onPressed: () async { onPressed: _clearCartAlert,
await clearCart();
setState(() {
cartItems = [];
});
},
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor, backgroundColor: Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(