Advertisement
Dordzhiev

order_view.dart

Jan 14th, 2023 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.07 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:intl/intl.dart';
  3. import 'package:provider/provider.dart';
  4.  
  5. import '../../shared/graphql_schema/schema.graphql.dart';
  6. import '../graphql_operations/fragments/fragments.graphql.dart';
  7. import '../view_models/order.viewmodel.dart';
  8. import 'components/arrival_time_row.dart';
  9. import 'components/button/button_component.dart';
  10. import 'components/payment_row.dart';
  11. import 'components/restaurant_title_address_block.dart';
  12.  
  13. class OrderPage extends StatefulWidget {
  14.   const OrderPage(this.order, {Key? key}) : super(key: key);
  15.  
  16.   final Fragment$Order order;
  17.  
  18.   @override
  19.   State<OrderPage> createState() => _OrderPageState();
  20. }
  21.  
  22. class _OrderPageState extends State<OrderPage> {
  23.   Fragment$Order? order;
  24.  
  25.   @override
  26.   void initState() {
  27.     super.initState();
  28.   }
  29.  
  30.   @override
  31.   Widget build(BuildContext context) {
  32.     order??= widget.order;
  33.     String actionName = '';
  34.     Enum$OrderStatus nextStatus = Enum$OrderStatus.DELIVERED;
  35.  
  36.     if ([Enum$OrderStatus.REGISTERED, Enum$OrderStatus.READY]
  37.         .contains(order!.status)) {
  38.       actionName = 'Забрал заказ';
  39.       nextStatus = Enum$OrderStatus.ON_THE_WAY;
  40.     } else if (order!.status == Enum$OrderStatus.ON_THE_WAY) {
  41.       if (!order!.prepayed || !order!.payed) {
  42.         actionName = 'Получил оплату';
  43.       } else {
  44.         actionName = 'Отдал заказ';
  45.       }
  46.       nextStatus = Enum$OrderStatus.DELIVERED;
  47.     }
  48.  
  49.     return Scaffold(
  50.       body: SafeArea(
  51.         child: Padding(
  52.           padding: const EdgeInsets.all(16.0),
  53.           child: Column(
  54.             children: <Widget>[
  55.               ArrivalTimeRow(order: order!),
  56.               const SizedBox(height: 16.0),
  57.               Row(
  58.                 children: [
  59.                   Text(
  60.                     '#${order!.id}',
  61.                     style: const TextStyle(color: Color(0xFF616161)),
  62.                   ),
  63.                   Expanded(child: Container()),
  64.                   Text(
  65.                     DateFormat('dd.mm.yyyy H:m').format(order!.createdAt),
  66.                     style: const TextStyle(
  67.                       color: Color(0xFF616161),
  68.                       fontSize: 12.0,
  69.                     ),
  70.                   ),
  71.                 ],
  72.               ),
  73.               const SizedBox(height: 12.0),
  74.               const Divider(
  75.                 color: Color(0xFFCECECE),
  76.                 thickness: 1.0,
  77.               ),
  78.               const SizedBox(height: 16.0),
  79.               RestaurantTitleAndAddressBlock(order: order!),
  80.               const SizedBox(height: 16.0),
  81.               Row(
  82.                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
  83.                 children: [
  84.                   const Text('Клиент:',
  85.                       style: TextStyle(fontWeight: FontWeight.w700)),
  86.                   Text(
  87.                     order!.number,
  88.                     style: const TextStyle(
  89.                       color: Color(0xFF1B3EBC),
  90.                       fontWeight: FontWeight.bold,
  91.                     ),
  92.                   )
  93.                 ],
  94.               ),
  95.               const SizedBox(height: 16.0),
  96.               if (order!.comment != null)
  97.                 Text(
  98.                   order!.comment!,
  99.                   style: const TextStyle(
  100.                     color: Color(0xFF616161),
  101.                     fontWeight: FontWeight.w600,
  102.                   ),
  103.                 ),
  104.               const Expanded(child: SizedBox.shrink()),
  105.               PaymentRow(order: order!),
  106.               const SizedBox(height: 16.0),
  107.               if (actionName.isNotEmpty)
  108.                 Button$orderStatusChange(
  109.                   actionName,
  110.                   onPressed: () {
  111.                       context.read<OrderListModel>().changeOrderStatus(
  112.                         order: widget.order,
  113.                         newStatus: nextStatus,
  114.                       ).then((value) => setState(()=>order=value));
  115.                   },
  116.                 ),
  117.             ],
  118.           ),
  119.         ),
  120.       ),
  121.     );
  122.   }
  123. }
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement