152 lines
4.6 KiB
Dart
152 lines
4.6 KiB
Dart
part of 'orderspage.dart';
|
||
|
||
class _Order extends StatelessWidget {
|
||
const _Order({
|
||
required this.order,
|
||
});
|
||
|
||
final Order order;
|
||
|
||
@override
|
||
Widget build(final BuildContext context) => InkWell(
|
||
onTap: () {
|
||
Navigator.of(context).push(
|
||
MaterialPageRoute(
|
||
builder: (final BuildContext context) => OrderDetails(order: order,),
|
||
),
|
||
);
|
||
},
|
||
child: Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||
height: 48,
|
||
child: Row(
|
||
children: [
|
||
Container(
|
||
width: 17,
|
||
height: 17,
|
||
decoration: const BoxDecoration(
|
||
color: Color.fromRGBO(
|
||
133,
|
||
200,
|
||
133,
|
||
100,
|
||
),
|
||
shape: BoxShape.circle,
|
||
),
|
||
),
|
||
const SizedBox(width: 20),
|
||
Expanded(
|
||
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(),
|
||
);
|
||
}
|