import 'dart:async'; import 'package:cubit_form/cubit_form.dart'; import 'package:selfprivacy/logic/courierscubit.dart'; import 'package:selfprivacy/models/courier.dart'; class CourierFormCubit extends FormCubit { CourierFormCubit({ required this.cubit, }) { name = FieldCubit( initalValue: 'Иван', validations: [ RequiredStringValidation('Поле обязательно'), ], ); surname = FieldCubit( initalValue: 'Иванов', validations: [ RequiredStringValidation('Поле обязательно'), ], ); phone = FieldCubit( initalValue: '88005553535', validations: [ RequiredStringValidation('Поле обязательно'), ], ); super.addFields([name, surname, phone]); } @override FutureOr onSubmit() { print('onSubmit'); print('name: ${name.state.value}'); print('surname: ${surname.state.value}'); print('phone: ${phone.state.value}'); final Courier courier = Courier( name: name.state.value, surname: name.state.value, phone: name.state.value, id: cubit.state.couriers.isEmpty ? 0 : cubit.state.couriers.last.id + 1, ); cubit.create(courier); } late FieldCubit name; late FieldCubit surname; late FieldCubit phone; final CouriersCubit cubit; }