feat(plans) Plans create and edit API connect, TextController management and redirect

This commit is contained in:
2024-05-13 17:15:07 +03:00
parent e7e48905cf
commit fb2ebe5a70
12 changed files with 659 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,21 @@
// ignore_for_file: must_be_immutable
part of 'plan_create_bloc.dart';
/// Abstract class for all events that can be dispatched from the
///PlanCreate widget.
///
/// Events must be immutable and implement the [Equatable] interface.
@immutable
abstract class PlanCreateEvent extends Equatable {}
/// Event that is dispatched when the PlanCreate widget is first created.
class PlanCreateInitialEvent extends PlanCreateEvent {
@override
List<Object?> get props => [];
}
class CreatePlan extends PlanCreateEvent {
@override
List<Object?> get props => [];
}

View File

@@ -0,0 +1,65 @@
// ignore_for_file: must_be_immutable
part of 'plan_create_bloc.dart';
/// Represents the state of PlanCreate in the application.
///
class PlanCreateState extends Equatable {
PlanCreateState({
this.planModelObj,
});
PlanCreateModel? planModelObj;
@override
List<Object?> get props => [planModelObj];
PlanCreateState copyWith({PlanCreateModel? planModelObj}) {
return PlanCreateState(
planModelObj: planModelObj ?? this.planModelObj,
);
}
}
class PlanCreateLoadedState extends PlanCreateState {
PlanCreateLoadedState({
this.planModelObj,
this.name,
this.details,
});
PlanCreateModel? planModelObj;
TextEditingController? name;
TextEditingController? details;
@override
List<Object?> get props => [
planModelObj,
name,
details,
];
PlanCreateLoadedState copyWith({
PlanCreateModel? planModelObj,
TextEditingController? name,
TextEditingController? details,
}) {
return PlanCreateLoadedState(
planModelObj: planModelObj ?? this.planModelObj,
name: name ?? this.name,
details: details ?? this.details,
);
}
}
class PlanCreateErrorState extends PlanCreateState {
final String errorMessage;
PlanCreateErrorState(this.errorMessage);
@override
List<Object> get props => [errorMessage];
}
class PlanCreateInitialState extends PlanCreateState {
PlanCreateInitialState({required PlanCreateModel planModelObj})
: super(planModelObj: planModelObj);
}

View File

@@ -0,0 +1,19 @@
// ignore_for_file: must_be_immutable
import 'package:equatable/equatable.dart';
/// This class defines the variables used in the [plan_create_screen],
/// and is typically used to hold data that is passed between different parts of the application.
class PlanCreateModel extends Equatable {
final String planID;
PlanCreateModel({required String planID}) : planID = planID;
PlanCreateModel copyWith(String planID) {
return PlanCreateModel(planID: planID);
}
@override
List<Object?> get props => [planID];
}

View File

@@ -0,0 +1,99 @@
import 'bloc/plan_create_bloc.dart';
import 'models/plan_create_model.dart';
import 'package:eatvio_app/core/app_export.dart';
import 'package:flutter/material.dart';
import 'package:eatvio_app/widgets/custom_bottom_bar.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
class PlanCreateScreen extends StatelessWidget {
const PlanCreateScreen({Key? key}) : super(key: key);
static Widget builder(BuildContext context) {
final planID = ModalRoute.of(context)!.settings.arguments;
return BlocProvider<PlanCreateBloc>(
create: (context) => PlanCreateBloc(PlanCreateState(
planModelObj: PlanCreateModel(planID: planID.toString())))
..add(PlanCreateInitialEvent()),
child: PlanCreateScreen());
}
Widget build(BuildContext context) {
return BlocBuilder<PlanCreateBloc, PlanCreateState>(
builder: (context, state) {
if (state is PlanCreateInitialState) {
// Это начальное состояние, данные ещё не загружены.
return Container(
color: Colors.white,
);
} else if (state is PlanCreateLoadedState) {
// Данные загружены, можно строить экран.
return _buildPlanCreate(context, state);
} else if (state is PlanCreateErrorState) {
// Произошла ошибка при загрузке данных.
return Center(child: Text(state.errorMessage));
} else {
// Другие состояния, если они есть.
return Container(); // Пустой контейнер для необработанных состояний.
}
},
);
}
_buildPlanCreate(BuildContext context, PlanCreateLoadedState state) {
mediaQueryData = MediaQuery.of(context);
return SafeArea(
child: Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
width: double.maxFinite,
decoration: AppDecoration.fillGray,
child: ListView(children: [
SizedBox(height: 30.v),
Container(
margin: EdgeInsets.only(
left: 16.h,
right: 20.h,
bottom: 10.h,
),
padding: EdgeInsets.all(12.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(12)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3),
),
],
),
child: Column(mainAxisSize: MainAxisSize.min, children: [
SizedBox(height: 16.0),
TextFormField(
controller: state.name,
decoration: InputDecoration(labelText: 'Заголовок'),
),
SizedBox(height: 16.0),
TextFormField(
controller: state.details,
decoration: InputDecoration(labelText: 'Описание'),
),
SizedBox(height: 16.0),
// Здесь нужно добавить виджет для загрузки картинки
ElevatedButton(
onPressed: () =>
context.read<PlanCreateBloc>().add(CreatePlan()),
child: Text('Создать'),
)
]),
)
]),
),
bottomNavigationBar: _buildBottomBar(context)));
}
}
_buildBottomBar(BuildContext context) {
return CustomBottomBar(onChanged: (BottomBarEnum type) {});
}