From 772f633d8b6078127bc107468279a85926976436 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Tue, 27 Dec 2022 10:37:39 +0400 Subject: [PATCH] feat: Implement items details --- lib/logic/courierformcubit.dart | 6 +-- lib/logic/itemformcubit.dart | 60 ++++++++++++++++++++++ lib/ui/itemsdetails.dart | 88 +++++++++++++++++++++++++++++++++ lib/ui/itemspage.dart | 1 + 4 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 lib/logic/itemformcubit.dart create mode 100644 lib/ui/itemsdetails.dart diff --git a/lib/logic/courierformcubit.dart b/lib/logic/courierformcubit.dart index 374d855..e843f60 100644 --- a/lib/logic/courierformcubit.dart +++ b/lib/logic/courierformcubit.dart @@ -9,20 +9,20 @@ class CourierFormCubit extends FormCubit { required this.cubit, }) { name = FieldCubit( - initalValue: 'Имя', + initalValue: 'Иван', validations: [ RequiredStringValidation('Поле обязательно'), ], ); surname = FieldCubit( - initalValue: 'Фамилия', + initalValue: 'Иванов', validations: [ RequiredStringValidation('Поле обязательно'), ], ); phone = FieldCubit( - initalValue: 'Телефон', + initalValue: '88005553535', validations: [ RequiredStringValidation('Поле обязательно'), ], diff --git a/lib/logic/itemformcubit.dart b/lib/logic/itemformcubit.dart new file mode 100644 index 0000000..6011956 --- /dev/null +++ b/lib/logic/itemformcubit.dart @@ -0,0 +1,60 @@ +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, + ); + + quantity = FieldCubit( + initalValue: 1, + ); + + super.addFields([title, description, price, quantity]); + } + + @override + FutureOr onSubmit() { + print('onSubmit'); + print('title: ${title.state.value}'); + print('description: ${description.state.value}'); + print('price: ${price.state.value}'); + print('quantity: ${quantity.state.value}'); + + final Item item = Item( + title: title.state.value, + description: description.state.value, + price: price.state.value, + quantity: quantity.state.value, + id: cubit.state.items.isEmpty ? 0 : cubit.state.items.last.id + 1, + ); + + cubit.create(item); + } + + late FieldCubit title; + late FieldCubit description; + late FieldCubit price; + late FieldCubit quantity; + + final ItemsCubit cubit; +} diff --git a/lib/ui/itemsdetails.dart b/lib/ui/itemsdetails.dart new file mode 100644 index 0000000..c959e86 --- /dev/null +++ b/lib/ui/itemsdetails.dart @@ -0,0 +1,88 @@ +part of 'itemspage.dart'; + +class ItemsDetails extends StatelessWidget { + const ItemsDetails({super.key}); + + @override + Widget build(final BuildContext context) => BrandBottomSheet( + child: BlocProvider( + create: (final BuildContext context) => ItemFormCubit( + cubit: context.read(), + ), + child: Builder( + builder: (final BuildContext context) => + BlocListener( + listener: + (final BuildContext context, final FormCubitState state) { + if (state.isSubmitted) { + Navigator.pop(context); + } + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + AppBar( + title: const Padding( + padding: EdgeInsets.only(top: 4.0), + child: Text('Новый товар!'), + ), + ), + const SizedBox(width: 14), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 15), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox(width: 14), + IntrinsicHeight( + child: CubitFormTextField( + formFieldCubit: context.read().title, + decoration: const InputDecoration( + labelText: 'Название', + ), + ), + ), + const SizedBox(height: 20), + CubitFormTextField( + formFieldCubit: + context.read().description, + decoration: const InputDecoration( + alignLabelWithHint: false, + labelText: 'Описание', + ), + ), + const SizedBox(height: 20), + CubitFormIntField( + formFieldCubit: context.read().price, + decoration: const InputDecoration( + alignLabelWithHint: false, + labelText: 'Цена', + ), + ), + const SizedBox(height: 20), + CubitFormIntField( + formFieldCubit: + context.read().quantity, + decoration: const InputDecoration( + alignLabelWithHint: false, + labelText: 'Количество', + ), + ), + const SizedBox(height: 30), + FilledButton( + onPressed: () => + context.read().trySubmit(), + title: 'Создать', + ), + const SizedBox(height: 40), + ], + ), + ), + ], + ), + ), + ), + ), + ); +} diff --git a/lib/ui/itemspage.dart b/lib/ui/itemspage.dart index 43c35cd..cf4d56e 100644 --- a/lib/ui/itemspage.dart +++ b/lib/ui/itemspage.dart @@ -4,6 +4,7 @@ import 'package:selfprivacy/logic/itemscubit.dart'; import 'package:selfprivacy/models/item.dart'; part 'item.dart'; +part 'itemsdetails.dart'; class ItemsPage extends StatelessWidget { const ItemsPage({super.key});