forked from eatvio/eatvio_app
feature(registration): remove .env
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/presentation/plans/plan_create_screen/models/plan_create_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import '/core/app_export.dart';
|
||||
import 'package:eatvio_app/presentation/plans/plan_create_screen/models/plan_create_model.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
part 'plan_create_event.dart';
|
||||
part 'plan_create_state.dart';
|
||||
|
||||
@@ -31,21 +32,27 @@ class PlanCreateBloc extends Bloc<PlanCreateEvent, PlanCreateState> {
|
||||
}
|
||||
if (state is PlanCreateLoadedState) {
|
||||
var currentState = state as PlanCreateLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
planModelObj: currentState.planModelObj,
|
||||
name: currentState.name,
|
||||
details: currentState.details,
|
||||
),);
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
planModelObj: currentState.planModelObj,
|
||||
name: currentState.name,
|
||||
details: currentState.details,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
emit(PlanCreateLoadedState(
|
||||
name: TextEditingController(),
|
||||
details: TextEditingController(),
|
||||
),);
|
||||
emit(
|
||||
PlanCreateLoadedState(
|
||||
name: TextEditingController(),
|
||||
details: TextEditingController(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _createPlan(
|
||||
CreatePlan event, Emitter<PlanCreateState> emit,) async {
|
||||
CreatePlan event,
|
||||
Emitter<PlanCreateState> emit,
|
||||
) async {
|
||||
if (state is PlanCreateLoadedState) {
|
||||
var currentState = state as PlanCreateLoadedState;
|
||||
|
||||
@@ -58,7 +65,8 @@ class PlanCreateBloc extends Bloc<PlanCreateEvent, PlanCreateState> {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('planSelectScreen');
|
||||
} else {
|
||||
print(
|
||||
'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}',);
|
||||
'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +75,7 @@ class PlanCreateBloc extends Bloc<PlanCreateEvent, PlanCreateState> {
|
||||
String? name,
|
||||
String? details,
|
||||
) async {
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/plans/create';
|
||||
String url = '${baseUrl}/api/plans/create';
|
||||
|
||||
final Map<String, dynamic> credentials = {
|
||||
'name': name,
|
||||
|
||||
@@ -60,6 +60,5 @@ class PlanCreateErrorState extends PlanCreateState {
|
||||
}
|
||||
|
||||
class PlanCreateInitialState extends PlanCreateState {
|
||||
PlanCreateInitialState({required PlanCreateModel planModelObj})
|
||||
: super(planModelObj: planModelObj);
|
||||
PlanCreateInitialState({required PlanCreateModel planModelObj}) : super(planModelObj: planModelObj);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
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 'bloc/plan_create_bloc.dart';
|
||||
import 'models/plan_create_model.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(),);
|
||||
create: (context) => PlanCreateBloc(PlanCreateState(planModelObj: PlanCreateModel(planID: planID.toString())))..add(PlanCreateInitialEvent()),
|
||||
child: PlanCreateScreen(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
@@ -65,24 +67,27 @@ class PlanCreateScreen extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
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('Создать'),
|
||||
),
|
||||
],),
|
||||
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('Создать'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user