57 lines
1.4 KiB
Dart
57 lines
1.4 KiB
Dart
|
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: 'Телефон',
|
||
|
validations: [
|
||
|
RequiredStringValidation('Поле обязательно'),
|
||
|
],
|
||
|
);
|
||
|
|
||
|
super.addFields([name, surname, phone]);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
FutureOr<void> 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<String> name;
|
||
|
late FieldCubit<String> surname;
|
||
|
late FieldCubit<String> phone;
|
||
|
|
||
|
final CouriersCubit cubit;
|
||
|
}
|