feat: Implement items details

This commit is contained in:
NaiJi 2022-12-27 10:37:39 +04:00
parent 5db7491b74
commit 772f633d8b
4 changed files with 152 additions and 3 deletions

View file

@ -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('Поле обязательно'),
],

View file

@ -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<void> 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<String> title;
late FieldCubit<String> description;
late FieldCubit<int> price;
late FieldCubit<int> quantity;
final ItemsCubit cubit;
}

88
lib/ui/itemsdetails.dart Normal file
View file

@ -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<ItemsCubit>(),
),
child: Builder(
builder: (final BuildContext context) =>
BlocListener<ItemFormCubit, FormCubitState>(
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<ItemFormCubit>().title,
decoration: const InputDecoration(
labelText: 'Название',
),
),
),
const SizedBox(height: 20),
CubitFormTextField(
formFieldCubit:
context.read<ItemFormCubit>().description,
decoration: const InputDecoration(
alignLabelWithHint: false,
labelText: 'Описание',
),
),
const SizedBox(height: 20),
CubitFormIntField(
formFieldCubit: context.read<ItemFormCubit>().price,
decoration: const InputDecoration(
alignLabelWithHint: false,
labelText: 'Цена',
),
),
const SizedBox(height: 20),
CubitFormIntField(
formFieldCubit:
context.read<ItemFormCubit>().quantity,
decoration: const InputDecoration(
alignLabelWithHint: false,
labelText: 'Количество',
),
),
const SizedBox(height: 30),
FilledButton(
onPressed: () =>
context.read<ItemFormCubit>().trySubmit(),
title: 'Создать',
),
const SizedBox(height: 40),
],
),
),
],
),
),
),
),
);
}

View file

@ -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});