feat: Implement couriers derails page
This commit is contained in:
parent
43fb58226d
commit
55c0d434cd
56
lib/logic/courierformcubit.dart
Normal file
56
lib/logic/courierformcubit.dart
Normal file
|
@ -0,0 +1,56 @@
|
|||
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;
|
||||
}
|
|
@ -25,9 +25,9 @@ class Courier extends Equatable {
|
|||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
name,
|
||||
surname,
|
||||
phone,
|
||||
id,
|
||||
];
|
||||
name,
|
||||
surname,
|
||||
phone,
|
||||
id,
|
||||
];
|
||||
}
|
||||
|
|
58
lib/ui/bottomsheet.dart
Normal file
58
lib/ui/bottomsheet.dart
Normal file
|
@ -0,0 +1,58 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class BrandBottomSheet extends StatelessWidget {
|
||||
const BrandBottomSheet({
|
||||
required this.child,
|
||||
super.key,
|
||||
this.isExpended = false,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final bool isExpended;
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
final double mainHeight = MediaQuery.of(context).size.height -
|
||||
MediaQuery.of(context).padding.top -
|
||||
100;
|
||||
late Widget innerWidget;
|
||||
if (isExpended) {
|
||||
innerWidget = Scaffold(
|
||||
body: child,
|
||||
);
|
||||
} else {
|
||||
final ThemeData themeData = Theme.of(context);
|
||||
|
||||
innerWidget = Material(
|
||||
color: themeData.scaffoldBackgroundColor,
|
||||
child: IntrinsicHeight(child: child),
|
||||
);
|
||||
}
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: mainHeight + 4 + 6),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
height: 4,
|
||||
width: 30,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
color: const Color.fromARGB(120, 120, 120, 100),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: mainHeight),
|
||||
child: innerWidget,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
41
lib/ui/button.dart
Normal file
41
lib/ui/button.dart
Normal file
|
@ -0,0 +1,41 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class FilledButton extends StatelessWidget {
|
||||
const FilledButton({
|
||||
super.key,
|
||||
this.onPressed,
|
||||
this.title,
|
||||
this.child,
|
||||
this.disabled = false,
|
||||
});
|
||||
|
||||
final VoidCallback? onPressed;
|
||||
final String? title;
|
||||
final Widget? child;
|
||||
final bool disabled;
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
final ButtonStyle enabledStyle = ElevatedButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0));
|
||||
|
||||
final ButtonStyle disabledStyle = ElevatedButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.onSurface.withAlpha(30),
|
||||
backgroundColor: Theme.of(context).colorScheme.onSurface.withAlpha(98),
|
||||
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0));
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 40,
|
||||
minWidth: double.infinity,
|
||||
),
|
||||
child: ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
style: disabled ? disabledStyle : enabledStyle,
|
||||
child: child ?? Text(title ?? ''),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -9,12 +9,13 @@ class _Courier extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(final BuildContext context) => InkWell(
|
||||
//onTap: () {
|
||||
//Navigator.of(context).push(
|
||||
// MaterialPageRoute(
|
||||
//builder: (final BuildContext context) => CourierDetails(courier),
|
||||
//);
|
||||
// },
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (final BuildContext context) => CouriersDetails(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
height: 48,
|
||||
|
@ -25,9 +26,9 @@ class _Courier extends StatelessWidget {
|
|||
height: 17,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color.fromRGBO(
|
||||
133,
|
||||
133,
|
||||
200,
|
||||
233,
|
||||
333,
|
||||
30,
|
||||
100,
|
||||
),
|
||||
shape: BoxShape.circle,
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
part of 'courierspage.dart';
|
||||
|
||||
class CouriersDetails extends StatelessWidget {
|
||||
const CouriersDetails({super.key});
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) => BrandBottomSheet(
|
||||
child: BlocProvider(
|
||||
create: (final BuildContext context) => CourierFormCubit(
|
||||
cubit: context.read<CouriersCubit>(),
|
||||
),
|
||||
child: Builder(
|
||||
builder: (final BuildContext context) =>
|
||||
BlocListener<CourierFormCubit, 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<CourierFormCubit>().name,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Имя',
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<CourierFormCubit>().surname,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Фамилия',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
CubitFormTextField(
|
||||
formFieldCubit:
|
||||
context.read<CourierFormCubit>().phone,
|
||||
decoration: const InputDecoration(
|
||||
alignLabelWithHint: false,
|
||||
labelText: 'Телефон',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
FilledButton(
|
||||
onPressed: () =>
|
||||
context.read<CourierFormCubit>().trySubmit(),
|
||||
title: 'Создать',
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
|
@ -1,9 +1,13 @@
|
|||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/logic/courierscubit.dart';
|
||||
import 'package:selfprivacy/logic/courierformcubit.dart';
|
||||
import 'package:selfprivacy/models/courier.dart';
|
||||
import 'package:selfprivacy/ui/bottomsheet.dart';
|
||||
import 'package:selfprivacy/ui/button.dart';
|
||||
|
||||
part 'courier.dart';
|
||||
part 'courierdetails.dart';
|
||||
|
||||
class CouriersPage extends StatelessWidget {
|
||||
const CouriersPage({super.key});
|
||||
|
|
Loading…
Reference in a new issue