forked from eatvio/eatvio_app
feature(registration): remove .env
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/presentation/diets/diet_create_screen/models/diet_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/diets/diet_create_screen/models/diet_create_model.dart';
|
||||
|
||||
part 'diet_create_event.dart';
|
||||
part 'diet_create_state.dart';
|
||||
@@ -32,21 +32,27 @@ class DietCreateBloc extends Bloc<DietCreateEvent, DietCreateState> {
|
||||
}
|
||||
if (state is DietCreateLoadedState) {
|
||||
var currentState = state as DietCreateLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
dietModelObj: currentState.dietModelObj,
|
||||
name: currentState.name,
|
||||
details: currentState.details,
|
||||
),);
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
dietModelObj: currentState.dietModelObj,
|
||||
name: currentState.name,
|
||||
details: currentState.details,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
emit(DietCreateLoadedState(
|
||||
name: TextEditingController(),
|
||||
details: TextEditingController(),
|
||||
),);
|
||||
emit(
|
||||
DietCreateLoadedState(
|
||||
name: TextEditingController(),
|
||||
details: TextEditingController(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _createDiet(
|
||||
CreateDiet event, Emitter<DietCreateState> emit,) async {
|
||||
CreateDiet event,
|
||||
Emitter<DietCreateState> emit,
|
||||
) async {
|
||||
if (state is DietCreateLoadedState) {
|
||||
var currentState = state as DietCreateLoadedState;
|
||||
|
||||
@@ -59,7 +65,8 @@ class DietCreateBloc extends Bloc<DietCreateEvent, DietCreateState> {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('dietSelectScreen');
|
||||
} else {
|
||||
print(
|
||||
'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}',);
|
||||
'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +75,7 @@ class DietCreateBloc extends Bloc<DietCreateEvent, DietCreateState> {
|
||||
String? name,
|
||||
String? details,
|
||||
) async {
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/diets/create';
|
||||
String url = '${baseUrl}/api/diets/create';
|
||||
|
||||
final Map<String, dynamic> credentials = {
|
||||
'name': name,
|
||||
|
||||
@@ -60,6 +60,5 @@ class DietCreateErrorState extends DietCreateState {
|
||||
}
|
||||
|
||||
class DietCreateInitialState extends DietCreateState {
|
||||
DietCreateInitialState({required DietCreateModel dietModelObj})
|
||||
: super(dietModelObj: dietModelObj);
|
||||
DietCreateInitialState({required DietCreateModel dietModelObj}) : super(dietModelObj: dietModelObj);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import 'bloc/diet_create_bloc.dart';
|
||||
import 'models/diet_create_model.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'bloc/diet_create_bloc.dart';
|
||||
import 'models/diet_create_model.dart';
|
||||
|
||||
class DietCreateScreen extends StatelessWidget {
|
||||
const DietCreateScreen({Key? key}) : super(key: key);
|
||||
|
||||
static Widget builder(BuildContext context) {
|
||||
final dietID = ModalRoute.of(context)!.settings.arguments;
|
||||
return BlocProvider<DietCreateBloc>(
|
||||
create: (context) => DietCreateBloc(DietCreateState(dietModelObj: DietCreateModel(dietID: dietID.toString())))..add(DietCreateInitialEvent()),
|
||||
child: DietCreateScreen(),);
|
||||
create: (context) => DietCreateBloc(DietCreateState(dietModelObj: DietCreateModel(dietID: dietID.toString())))..add(DietCreateInitialEvent()),
|
||||
child: DietCreateScreen(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
@@ -43,47 +45,52 @@ class DietCreateScreen extends StatelessWidget {
|
||||
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,
|
||||
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<DietCreateBloc>().add(CreateDiet()),
|
||||
child: Text('Создать'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
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<DietCreateBloc>().add(CreateDiet()),
|
||||
child: Text('Создать'),
|
||||
),
|
||||
],),
|
||||
),
|
||||
],),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user