2022-12-27 06:37:39 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
|
|
import 'package:selfprivacy/logic/itemscubit.dart';
|
|
|
|
import 'package:selfprivacy/models/item.dart';
|
|
|
|
|
|
|
|
class ItemFormCubit extends FormCubit {
|
|
|
|
ItemFormCubit({
|
|
|
|
required this.cubit,
|
|
|
|
}) {
|
|
|
|
title = FieldCubit(
|
|
|
|
initalValue: 'Товар',
|
|
|
|
validations: [
|
|
|
|
RequiredStringValidation('Поле обязательно'),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
description = FieldCubit(
|
|
|
|
initalValue: ' ',
|
|
|
|
validations: [
|
|
|
|
RequiredStringValidation('Поле обязательно'),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
price = FieldCubit(
|
|
|
|
initalValue: 100,
|
|
|
|
);
|
|
|
|
|
2022-12-27 08:41:20 +00:00
|
|
|
super.addFields([title, description, price]);
|
2022-12-27 06:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
FutureOr<void> onSubmit() {
|
|
|
|
print('onSubmit');
|
|
|
|
print('title: ${title.state.value}');
|
|
|
|
print('description: ${description.state.value}');
|
|
|
|
print('price: ${price.state.value}');
|
|
|
|
|
|
|
|
final Item item = Item(
|
|
|
|
title: title.state.value,
|
|
|
|
description: description.state.value,
|
|
|
|
price: price.state.value,
|
|
|
|
id: cubit.state.items.isEmpty ? 0 : cubit.state.items.last.id + 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
cubit.create(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
late FieldCubit<String> title;
|
|
|
|
late FieldCubit<String> description;
|
|
|
|
late FieldCubit<int> price;
|
|
|
|
|
|
|
|
final ItemsCubit cubit;
|
|
|
|
}
|