course-work/lib/logic/courierformcubit.dart

57 lines
1.4 KiB
Dart
Raw Normal View History

2022-12-27 06:23:01 +00:00
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(
2022-12-27 06:37:39 +00:00
initalValue: 'Иван',
2022-12-27 06:23:01 +00:00
validations: [
RequiredStringValidation('Поле обязательно'),
],
);
surname = FieldCubit(
2022-12-27 06:37:39 +00:00
initalValue: 'Иванов',
2022-12-27 06:23:01 +00:00
validations: [
RequiredStringValidation('Поле обязательно'),
],
);
phone = FieldCubit(
2022-12-27 06:37:39 +00:00
initalValue: '88005553535',
2022-12-27 06:23:01 +00:00
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;
}