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 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 title; late FieldCubit description; late FieldCubit customerName; late FieldCubit customerPhone; late FieldCubit orderDate; late FieldCubit deliveryDate; late FieldCubit address; final OrdersCubit cubit; }