feat: Implement order
This commit is contained in:
parent
f094883840
commit
0c1adbadd0
102
lib/logic/orderformcubit.dart
Normal file
102
lib/logic/orderformcubit.dart
Normal file
|
@ -0,0 +1,102 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:selfprivacy/logic/orderscubit.dart';
|
||||
import 'package:selfprivacy/models/item.dart';
|
||||
import 'package:selfprivacy/models/order.dart';
|
||||
|
||||
class OrderFormCubit extends FormCubit {
|
||||
OrderFormCubit({
|
||||
required this.cubit,
|
||||
}) {
|
||||
title = FieldCubit(
|
||||
initalValue: 'Заказ...',
|
||||
validations: [
|
||||
RequiredStringValidation('Поле обязательно'),
|
||||
],
|
||||
);
|
||||
description = FieldCubit(
|
||||
initalValue: ' ',
|
||||
validations: [
|
||||
RequiredStringValidation('Поле обязательно'),
|
||||
],
|
||||
);
|
||||
address = FieldCubit(
|
||||
initalValue: ' ',
|
||||
validations: [
|
||||
RequiredStringValidation('Поле обязательно'),
|
||||
],
|
||||
);
|
||||
customerName = FieldCubit(
|
||||
initalValue: 'Иван',
|
||||
validations: [
|
||||
RequiredStringValidation('Поле обязательно'),
|
||||
],
|
||||
);
|
||||
customerPhone = FieldCubit(
|
||||
initalValue: '88005553535',
|
||||
validations: [
|
||||
RequiredStringValidation('Поле обязательно'),
|
||||
],
|
||||
);
|
||||
orderDate = FieldCubit(
|
||||
initalValue: ' ',
|
||||
validations: [
|
||||
RequiredStringValidation('Поле обязательно'),
|
||||
],
|
||||
);
|
||||
deliveryDate = FieldCubit(
|
||||
initalValue: ' ',
|
||||
validations: [
|
||||
RequiredStringValidation('Поле обязательно'),
|
||||
],
|
||||
);
|
||||
super.addFields([
|
||||
title,
|
||||
description,
|
||||
address,
|
||||
orderDate,
|
||||
deliveryDate,
|
||||
customerName,
|
||||
customerPhone,
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOr<void> onSubmit() {
|
||||
print('onSubmit');
|
||||
print('title: ${title.state.value}');
|
||||
print('description: ${description.state.value}');
|
||||
print('address: ${address.state.value}');
|
||||
print('orderdate: ${orderDate.state.value}');
|
||||
print('deliverydate: ${deliveryDate.state.value}');
|
||||
print('cusname: ${customerName.state.value}');
|
||||
print('cusphone: ${customerPhone.state.value}');
|
||||
|
||||
final Order item = Order(
|
||||
courierId: 0,
|
||||
items: [],
|
||||
status: 'error',
|
||||
title: title.state.value,
|
||||
description: description.state.value,
|
||||
address: address.state.value,
|
||||
orderDate: orderDate.state.value,
|
||||
deliveryDate: deliveryDate.state.value,
|
||||
customerName: customerName.state.value,
|
||||
customerPhone: customerPhone.state.value,
|
||||
id: cubit.state.orders.isEmpty ? 0 : cubit.state.orders.last.id + 1,
|
||||
);
|
||||
|
||||
cubit.create(item);
|
||||
}
|
||||
|
||||
late FieldCubit<String> title;
|
||||
late FieldCubit<String> description;
|
||||
late FieldCubit<String> customerName;
|
||||
late FieldCubit<String> customerPhone;
|
||||
late FieldCubit<String> orderDate;
|
||||
late FieldCubit<String> deliveryDate;
|
||||
late FieldCubit<String> address;
|
||||
|
||||
final OrdersCubit cubit;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/ui/orderspage.dart';
|
||||
|
||||
class AddOrderFab extends StatelessWidget {
|
||||
const AddOrderFab({super.key});
|
||||
|
@ -13,8 +14,7 @@ class AddOrderFab extends StatelessWidget {
|
|||
backgroundColor: Colors.transparent,
|
||||
builder: (final BuildContext context) => Padding(
|
||||
padding: MediaQuery.of(context).viewInsets,
|
||||
child:
|
||||
null, // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111
|
||||
child: const OrdersDetails(),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
117
lib/ui/ordersdetails.dart
Normal file
117
lib/ui/ordersdetails.dart
Normal file
|
@ -0,0 +1,117 @@
|
|||
part of 'orderspage.dart';
|
||||
|
||||
class OrdersDetails extends StatelessWidget {
|
||||
const OrdersDetails({super.key});
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) => BrandBottomSheet(
|
||||
child: BlocProvider(
|
||||
create: (final BuildContext context) => OrderFormCubit(
|
||||
cubit: context.read<OrdersCubit>(),
|
||||
),
|
||||
child: Builder(
|
||||
builder: (final BuildContext context) =>
|
||||
BlocListener<OrderFormCubit, FormCubitState>(
|
||||
listener:
|
||||
(final BuildContext context, final FormCubitState state) {
|
||||
if (state.isSubmitted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AppBar(
|
||||
title: const Padding(
|
||||
padding: EdgeInsets.only(top: 4.0),
|
||||
child: Text('Новый заказ!'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(width: 14),
|
||||
IntrinsicHeight(
|
||||
child: CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<OrderFormCubit>().title,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Наименование',
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<OrderFormCubit>().description,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Описание',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<OrderFormCubit>().address,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Адрес доставки',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<OrderFormCubit>().customerName,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Имя заказчика',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<OrderFormCubit>().customerPhone,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Телефон заказчика',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<OrderFormCubit>().orderDate,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Дата заказа',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<OrderFormCubit>().deliveryDate,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Дата доставки',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: () =>
|
||||
context.read<OrderFormCubit>().trySubmit(),
|
||||
title: 'Создать',
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/logic/courierscubit.dart';
|
||||
import 'package:selfprivacy/logic/orderformcubit.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/ui/bottomsheet.dart';
|
||||
import 'package:selfprivacy/ui/button.dart';
|
||||
|
||||
part 'order.dart';
|
||||
part 'ordersdetails.dart';
|
||||
|
||||
class OrdersPage extends StatelessWidget {
|
||||
const OrdersPage({super.key});
|
||||
|
|
Loading…
Reference in a new issue