order showcase
This commit is contained in:
parent
96d70a6725
commit
43fb58226d
|
@ -10,10 +10,11 @@ class _Order extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) => InkWell(
|
Widget build(final BuildContext context) => InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
// MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
// builder: (final BuildContext context) => OrderDetails(order),
|
builder: (final BuildContext context) => OrderDetails(order: order,),
|
||||||
// );
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||||
|
@ -34,11 +35,117 @@ class _Order extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 20),
|
const SizedBox(width: 20),
|
||||||
Flexible(
|
Expanded(
|
||||||
child: Text(order.title),
|
child: Flexible(
|
||||||
|
child: Text(order.title),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: 20),
|
||||||
|
OrderStatusChip(status: order.status),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class OrderDetails extends StatelessWidget {
|
||||||
|
const OrderDetails({
|
||||||
|
required this.order,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Order order;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final Courier? courier = context.watch<CouriersCubit>().state.couriers.firstWhere((final Courier courier) => courier.id == order.courierId);
|
||||||
|
final int price = order.items.fold(0, (final int previousValue, final Item item) => previousValue + (item.price ?? 0));
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(order.title),
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
children: [
|
||||||
|
// Order name
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text(order.title, style: Theme.of(context).textTheme.headlineMedium)),
|
||||||
|
// Order description
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text(order.description, style: Theme.of(context).textTheme.titleSmall)),
|
||||||
|
// Order status
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: OrderStatusChip(status: order.status)),
|
||||||
|
// Order courier
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Курьер: ${courier?.name ?? 'Не назначен'} ${courier?.surname ?? ''}')),
|
||||||
|
// Created at
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Создано: ${order.orderDate}')),
|
||||||
|
// Delivery date
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Доставка: ${order.deliveryDate}')),
|
||||||
|
// Customer name
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Заказчик: ${order.customerName}')),
|
||||||
|
// Customer phone
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Телефон: ${order.customerPhone}')),
|
||||||
|
// Customer address
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Адрес: ${order.address}')),
|
||||||
|
// Order price
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Цена: ${price} руб.')),
|
||||||
|
// Order items
|
||||||
|
Padding(padding: const EdgeInsets.all(15), child: Text('Товары:')),
|
||||||
|
...order.items.map((final Item item) => Padding(padding: const EdgeInsets.all(15), child: Text('${item.title} - ${item.price ?? 0} руб.'))),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderStatusChip extends StatelessWidget {
|
||||||
|
const OrderStatusChip({
|
||||||
|
required this.status,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String status;
|
||||||
|
|
||||||
|
// created
|
||||||
|
// packaged
|
||||||
|
// in_delivery
|
||||||
|
// delivered
|
||||||
|
// cancelled
|
||||||
|
|
||||||
|
Color _getChipColor() {
|
||||||
|
switch (status) {
|
||||||
|
case 'created':
|
||||||
|
return Colors.grey;
|
||||||
|
case 'packaged':
|
||||||
|
return Colors.blue;
|
||||||
|
case 'in_delivery':
|
||||||
|
return Colors.green;
|
||||||
|
case 'delivered':
|
||||||
|
return Colors.green;
|
||||||
|
case 'cancelled':
|
||||||
|
return Colors.red;
|
||||||
|
default:
|
||||||
|
return Colors.grey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getChipText() {
|
||||||
|
switch (status) {
|
||||||
|
case 'created':
|
||||||
|
return 'Создан';
|
||||||
|
case 'packaged':
|
||||||
|
return 'Упакован';
|
||||||
|
case 'in_delivery':
|
||||||
|
return 'В пути';
|
||||||
|
case 'delivered':
|
||||||
|
return 'Доставлен';
|
||||||
|
case 'cancelled':
|
||||||
|
return 'Отменен';
|
||||||
|
default:
|
||||||
|
return 'Неизвестно';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Chip(
|
||||||
|
label: Text(_getChipText()),
|
||||||
|
backgroundColor: _getChipColor(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:selfprivacy/logic/courierscubit.dart';
|
||||||
import 'package:selfprivacy/logic/orderscubit.dart';
|
import 'package:selfprivacy/logic/orderscubit.dart';
|
||||||
|
import 'package:selfprivacy/models/courier.dart';
|
||||||
|
import 'package:selfprivacy/models/item.dart';
|
||||||
import 'package:selfprivacy/models/order.dart';
|
import 'package:selfprivacy/models/order.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
part 'order.dart';
|
part 'order.dart';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue