Compare commits

...

3 Commits

Author SHA1 Message Date
e4628e977f Added tODO 2024-05-03 16:00:49 +03:00
4bbe7fbc0b Clearing shopping cart 2024-05-03 13:59:06 +03:00
5c3da0964a Added order history cards 2024-05-03 13:58:46 +03:00
6 changed files with 246 additions and 12 deletions

View File

@@ -0,0 +1,79 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
enum OrderStatus { created, inProgress, completed, canceled }
Map<OrderStatus, String> orderStatusMap = {
OrderStatus.created: 'Создан',
OrderStatus.inProgress: 'В обработке',
OrderStatus.completed: 'Завершен',
OrderStatus.canceled: 'Отменен',
};
class HistoryItemCard extends StatelessWidget {
final String id;
final String cost;
final String date;
final Image image;
final OrderStatus status;
const HistoryItemCard({
super.key,
required this.id,
required this.cost,
required this.date,
required this.status,
required this.image,
});
@override
Widget build(BuildContext context) {
return Padding(
padding:
const EdgeInsetsDirectional.symmetric(horizontal: 10, vertical: 10),
child: ConstrainedBox(
constraints: const BoxConstraints(
minHeight: 100,
maxHeight: 200,
minWidth: 400,
maxWidth: 600,
),
child: Card(
elevation: 4,
color: const Color(0xFFF2F3F9),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
child: Padding(
padding: const EdgeInsetsDirectional.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
image,
const SizedBox(width: 20),
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MarkdownBody(
data: '### Заказ **№$id** от $date',
),
MarkdownBody(
data: 'Статус: **${orderStatusMap[status]}**'),
MarkdownBody(data: 'Сумма: **\$$cost**'),
],
)
],
),
],
),
),
),
),
);
}
}

View File

@@ -32,9 +32,15 @@ class ProductCard extends StatelessWidget {
children: [
imagePath,
const SizedBox(height: 16),
Text(name, style: Theme.of(context).textTheme.titleLarge),
Text(
name,
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 8),
Text('\$$price', style: Theme.of(context).textTheme.titleSmall),
Text(
'\$$price',
style: Theme.of(context).textTheme.titleSmall,
),
],
),
),

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']),
);
},
),
@@ -151,6 +223,18 @@ class _BasketPageState extends State<BasketPage> {
),
child: const Text('Оформить заказ'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _clearCartAlert,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(50))),
foregroundColor: Colors.white,
),
child: const Text('Очистить корзину'),
),
],
),
),

View File

@@ -1,6 +1,40 @@
import 'package:flutter/material.dart';
import 'package:gymlink_module_web/components/app_bar.dart';
import 'package:gymlink_module_web/components/heading.dart';
import 'package:gymlink_module_web/components/history_item_card.dart';
List<Map<String, String>> orders = [
{
"image": "product.png",
"price": "120",
"id": "34fa3126-bfaf-5dec-8f4a-b246c097ef73",
"date": "11.09.2001"
},
{
"image": "product.png",
"price": "150",
"id": "34a26e82-7656-5e98-a44a-c2d01d0b1ad1123",
"date": "11.09.2001",
},
{
"image": "product.png",
"price": "250",
"id": "4fb204b7-3f9e-52a2-bed1-415c00a31a37123",
"date": "11.09.2001",
},
{
"image": "product.png",
"price": "300",
"id": "09b2f5bb-683e-5c39-ae89-b8e152fa8bcf123",
"date": "11.09.2001",
},
{
"image": "product.png",
"price": "100",
"id": "cd1b6817-db94-5394-be1d-af88af79749f123",
"date": "11.09.2001",
}
];
class HistoryPage extends StatelessWidget {
const HistoryPage({
@@ -8,14 +42,39 @@ class HistoryPage extends StatelessWidget {
});
@override
Widget build(BuildContext context) {
return const Scaffold(
appBar: GymLinkAppBar(),
body: Column(mainAxisAlignment: MainAxisAlignment.start, children: [
GymLinkHeader(title: 'История заказов'),
Center(
child: Text('История заказов'),
)
]),
return Scaffold(
appBar: const GymLinkAppBar(),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const GymLinkHeader(title: 'История заказов'),
Expanded(
child: Row(
children: [
Expanded(
child: ListView.builder(
itemCount: orders.length,
itemBuilder: (context, index) {
final item = orders[index];
return HistoryItemCard(
id: item['id']!,
cost: item['price']!,
date: item['date']!,
image: Image.asset(
item['image']!,
width: 50,
),
status: OrderStatus.completed,
);
},
),
),
const Spacer(),
],
),
),
],
),
);
}
}

View File

@@ -40,3 +40,8 @@ Future<void> removeItemFromCart(String id) async {
}
prefs.setString('cart', jsonEncode(cart));
}
Future<void> clearCart() async {
final prefs = await SharedPreferences.getInstance();
prefs.setString('cart', "[]");
}

View File

@@ -37,6 +37,7 @@ dependencies:
cupertino_icons: ^1.0.6
url_launcher: ^6.2.6
shared_preferences: ^2.2.3
flutter_markdown: ^0.7.1
dev_dependencies:
flutter_test: