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/recipe/recipe_create_screen/models/recipe_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/recipe/recipe_create_screen/models/recipe_create_model.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
part 'recipe_create_event.dart';
|
||||
part 'recipe_create_state.dart';
|
||||
|
||||
@@ -34,7 +35,8 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
||||
}
|
||||
if (state is RecipeCreateLoadedState) {
|
||||
var currentState = state as RecipeCreateLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
recipeModelObj: currentState.recipeModelObj,
|
||||
title: currentState.title,
|
||||
token: currentState.token,
|
||||
@@ -42,62 +44,79 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
||||
video_url: currentState.video_url,
|
||||
steps: currentState.steps,
|
||||
stepDescriptions: currentState.stepDescriptions,
|
||||
tags: currentState.tags,),);
|
||||
tags: currentState.tags,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final Map<String, dynamic> step = {
|
||||
'description': '',
|
||||
'image': '',
|
||||
};
|
||||
emit(RecipeCreateLoadedState(
|
||||
emit(
|
||||
RecipeCreateLoadedState(
|
||||
token: token,
|
||||
title: TextEditingController(),
|
||||
description: TextEditingController(),
|
||||
video_url: TextEditingController(),
|
||||
tags: TextEditingController(),
|
||||
stepDescriptions: [TextEditingController()],
|
||||
steps: [step],),);
|
||||
steps: [step],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _addStep(
|
||||
AddStep event, Emitter<RecipeCreateState> emit,) async {
|
||||
AddStep event,
|
||||
Emitter<RecipeCreateState> emit,
|
||||
) async {
|
||||
if (state is RecipeCreateLoadedState) {
|
||||
var currentState = state as RecipeCreateLoadedState;
|
||||
|
||||
List<dynamic>? updatedSteps = currentState.steps;
|
||||
List<TextEditingController>? updatedStepDescriptions =
|
||||
currentState.stepDescriptions;
|
||||
List<TextEditingController>? updatedStepDescriptions = currentState.stepDescriptions;
|
||||
|
||||
updatedSteps!.add({
|
||||
'description': '',
|
||||
'image': '',
|
||||
});
|
||||
updatedStepDescriptions!.add(TextEditingController());
|
||||
emit(currentState.copyWith(
|
||||
steps: updatedSteps, stepDescriptions: updatedStepDescriptions,),);
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
steps: updatedSteps,
|
||||
stepDescriptions: updatedStepDescriptions,
|
||||
),
|
||||
);
|
||||
await _reloadScreen(event, emit);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeStep(
|
||||
RemoveStep event, Emitter<RecipeCreateState> emit,) async {
|
||||
RemoveStep event,
|
||||
Emitter<RecipeCreateState> emit,
|
||||
) async {
|
||||
if (state is RecipeCreateLoadedState) {
|
||||
var currentState = state as RecipeCreateLoadedState;
|
||||
|
||||
List<dynamic>? updatedSteps = currentState.steps;
|
||||
List<TextEditingController>? updatedStepDescriptions =
|
||||
currentState.stepDescriptions;
|
||||
List<TextEditingController>? updatedStepDescriptions = currentState.stepDescriptions;
|
||||
|
||||
updatedSteps!.removeAt(event.id);
|
||||
updatedStepDescriptions!.removeAt(event.id);
|
||||
emit(currentState.copyWith(
|
||||
steps: updatedSteps, stepDescriptions: updatedStepDescriptions,),);
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
steps: updatedSteps,
|
||||
stepDescriptions: updatedStepDescriptions,
|
||||
),
|
||||
);
|
||||
await _reloadScreen(event, emit);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _createRecipe(
|
||||
CreateRecipe event, Emitter<RecipeCreateState> emit,) async {
|
||||
CreateRecipe event,
|
||||
Emitter<RecipeCreateState> emit,
|
||||
) async {
|
||||
if (state is RecipeCreateLoadedState) {
|
||||
var currentState = state as RecipeCreateLoadedState;
|
||||
|
||||
@@ -112,14 +131,19 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('recipeSelectScreen');
|
||||
} else {
|
||||
print(
|
||||
'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}',);
|
||||
'Failed to create blog post. Status Code: ${response.statusCode} ${response.body}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<http.Response> sendRecipe(String? title, String? video_url,
|
||||
String? description, List<dynamic>? steps,) async {
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/recipe/create';
|
||||
FutureOr<http.Response> sendRecipe(
|
||||
String? title,
|
||||
String? video_url,
|
||||
String? description,
|
||||
List<dynamic>? steps,
|
||||
) async {
|
||||
String url = '${baseUrl}/api/recipe/create';
|
||||
final Map<String, dynamic> credentials = {
|
||||
'title': title,
|
||||
'description': description,
|
||||
@@ -141,7 +165,9 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
||||
}
|
||||
|
||||
FutureOr<void> _reloadScreen(
|
||||
RecipeCreateEvent? event, Emitter<RecipeCreateState> emit,) async {
|
||||
RecipeCreateEvent? event,
|
||||
Emitter<RecipeCreateState> emit,
|
||||
) async {
|
||||
print('Reloading..');
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
@@ -150,7 +176,8 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
||||
}
|
||||
if (state is RecipeCreateLoadedState) {
|
||||
var currentState = state as RecipeCreateLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
recipeModelObj: currentState.recipeModelObj,
|
||||
title: currentState.title,
|
||||
token: currentState.token,
|
||||
@@ -158,7 +185,9 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
||||
video_url: currentState.video_url,
|
||||
steps: currentState.steps,
|
||||
stepDescriptions: currentState.stepDescriptions,
|
||||
tags: currentState.tags,),);
|
||||
tags: currentState.tags,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,16 @@ class RecipeCreateState extends Equatable {
|
||||
}
|
||||
|
||||
class RecipeCreateLoadedState extends RecipeCreateState {
|
||||
RecipeCreateLoadedState(
|
||||
{this.recipeModelObj,
|
||||
this.token,
|
||||
this.title,
|
||||
this.description,
|
||||
this.video_url,
|
||||
this.tags,
|
||||
this.stepDescriptions,
|
||||
this.steps,});
|
||||
RecipeCreateLoadedState({
|
||||
this.recipeModelObj,
|
||||
this.token,
|
||||
this.title,
|
||||
this.description,
|
||||
this.video_url,
|
||||
this.tags,
|
||||
this.stepDescriptions,
|
||||
this.steps,
|
||||
});
|
||||
|
||||
RecipeCreateModel? recipeModelObj;
|
||||
String? token;
|
||||
@@ -62,14 +63,15 @@ class RecipeCreateLoadedState extends RecipeCreateState {
|
||||
List<TextEditingController>? stepDescriptions,
|
||||
}) {
|
||||
return RecipeCreateLoadedState(
|
||||
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
video_url: video_url ?? this.video_url,
|
||||
token: token ?? this.token,
|
||||
steps: steps ?? this.steps,
|
||||
tags: tags ?? this.tags,
|
||||
stepDescriptions: stepDescriptions ?? this.stepDescriptions,);
|
||||
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
video_url: video_url ?? this.video_url,
|
||||
token: token ?? this.token,
|
||||
steps: steps ?? this.steps,
|
||||
tags: tags ?? this.tags,
|
||||
stepDescriptions: stepDescriptions ?? this.stepDescriptions,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +85,5 @@ class RecipeCreateErrorState extends RecipeCreateState {
|
||||
}
|
||||
|
||||
class RecipeCreateInitialState extends RecipeCreateState {
|
||||
RecipeCreateInitialState({required RecipeCreateModel recipeModelObj})
|
||||
: super(recipeModelObj: recipeModelObj);
|
||||
RecipeCreateInitialState({required RecipeCreateModel recipeModelObj}) : super(recipeModelObj: recipeModelObj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user