From 5c3da0964a1ef65107db5b087cb0ee8e084ab752 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Fri, 3 May 2024 13:58:46 +0300 Subject: [PATCH] Added order history cards --- lib/components/history_item_card.dart | 79 +++++++++++++++++++++++++++ lib/components/item_card.dart | 10 +++- lib/pages/order_history.dart | 75 ++++++++++++++++++++++--- pubspec.yaml | 1 + 4 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 lib/components/history_item_card.dart diff --git a/lib/components/history_item_card.dart b/lib/components/history_item_card.dart new file mode 100644 index 0000000..12d1e93 --- /dev/null +++ b/lib/components/history_item_card.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; + +enum OrderStatus { created, inProgress, completed, canceled } + +Map 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**'), + ], + ) + ], + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/components/item_card.dart b/lib/components/item_card.dart index da8d14a..cdd3f01 100644 --- a/lib/components/item_card.dart +++ b/lib/components/item_card.dart @@ -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, + ), ], ), ), diff --git a/lib/pages/order_history.dart b/lib/pages/order_history.dart index 574897f..d69159e 100644 --- a/lib/pages/order_history.dart +++ b/lib/pages/order_history.dart @@ -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> 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(), + ], + ), + ), + ], + ), ); } } diff --git a/pubspec.yaml b/pubspec.yaml index 3baf9d5..fac9096 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: