course-work/lib/logic/orderformcubit.dart

103 lines
2.8 KiB
Dart
Raw Normal View History

2022-12-27 09:09:00 +00:00
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;
}