forked from eatvio/eatvio_app
refactor(token): add token storage, remove hive
This commit is contained in:
@@ -6,7 +6,6 @@ import 'package:eatvio_app/widgets/app_bar/appbar_title_image.dart';
|
||||
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:validators/validators.dart';
|
||||
@@ -167,9 +166,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
print(response.statusCode);
|
||||
if (response.statusCode == 200) {
|
||||
var res = await jsonDecode(response.body);
|
||||
final box = await Hive.openBox('token');
|
||||
final token = res['token'];
|
||||
box.put('token', token);
|
||||
await TokenStorage.saveTokenInStorage(token);
|
||||
GoRouter.of(context).go('/my-profile-screen');
|
||||
} else {
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.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:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -25,9 +25,7 @@ class DietCreateBloc extends Bloc<DietCreateEvent, DietCreateState> {
|
||||
DietCreateInitialEvent event,
|
||||
Emitter<DietCreateState> emit,
|
||||
) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
if (state is DietCreateLoadedState) {
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/diets/diet_edit_screen/models/diet_edit_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,16 +26,14 @@ class DietEditBloc extends Bloc<DietEditEvent, DietEditState> {
|
||||
Emitter<DietEditState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final String? dietID = state.dietModelObj?.dietID;
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/diets/show/$dietID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/diets/diet_select_screen/models/diet_select_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
@@ -27,15 +27,13 @@ class DietSelectBloc extends Bloc<DietSelectEvent, DietSelectState> {
|
||||
Emitter<DietSelectState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/diets/index'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
print('Got response');
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/diets/diet_show_screen/models/diet_show_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,16 +26,14 @@ class DietBloc extends Bloc<DietEvent, DietState> {
|
||||
Emitter<DietState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final String? dietID = state.dietModelObj?.dietID;
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/diets/show/$dietID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -62,16 +60,14 @@ class DietBloc extends Bloc<DietEvent, DietState> {
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteEntry(DeleteEntry event, Emitter<DietState> emit) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final int id = event.id;
|
||||
final response = await http.post(
|
||||
Uri.parse(baseUrl + '/api/diets/delete/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
@@ -2,12 +2,12 @@ import 'dart:async';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
import 'package:eatvio_app/presentation/feed/blog_post_create_screen/models/blog_post_create_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -27,9 +27,7 @@ class BlogPostCreateBloc extends Bloc<BlogPostCreateEvent, BlogPostCreateState>
|
||||
BlogPostCreateInitialEvent event,
|
||||
Emitter<BlogPostCreateState> emit,
|
||||
) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
if (state is BlogPostCreateLoadedState) {
|
||||
@@ -46,7 +44,7 @@ class BlogPostCreateBloc extends Bloc<BlogPostCreateEvent, BlogPostCreateState>
|
||||
} else {
|
||||
emit(
|
||||
BlogPostCreateLoadedState(
|
||||
token: token,
|
||||
token: await TokenStorage.getTokenFromStorage(),
|
||||
title: TextEditingController(),
|
||||
description: TextEditingController(),
|
||||
youtubeURL: TextEditingController(),
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/feed/blog_post_edit_screen/models/blog_post_edit_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,16 +26,14 @@ class BlogPostEditBloc extends Bloc<BlogPostEditEvent, BlogPostEditState> {
|
||||
Emitter<BlogPostEditState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final String? blog_postID = state.blog_postModelObj?.blog_postID;
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/blogPosts/show/$blog_postID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/glossary/glossary_screen/models/glossary_screen_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,15 +26,13 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
Emitter<GlossaryState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final responseProductGroups = await http.get(
|
||||
Uri.parse(baseUrl + '/api/glossaries/group/index'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (responseProductGroups.statusCode == 200) {
|
||||
@@ -54,12 +52,12 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
List<SelectionPopupModel> productGroupsModel = _fillProductGroups(dataProductGroups);
|
||||
emit(
|
||||
GlossaryLoadedState(
|
||||
token: token,
|
||||
token: await TokenStorage.getTokenFromStorage(),
|
||||
productGroups: productGroupsModel,
|
||||
productList: [],
|
||||
),
|
||||
);
|
||||
await _getProductListById(token, emit, productGroupsModel[0].id);
|
||||
await _getProductListById(await TokenStorage.getTokenFromStorage(), emit, productGroupsModel[0].id);
|
||||
}
|
||||
} else {
|
||||
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.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:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -25,9 +25,7 @@ class PlanCreateBloc extends Bloc<PlanCreateEvent, PlanCreateState> {
|
||||
PlanCreateInitialEvent event,
|
||||
Emitter<PlanCreateState> emit,
|
||||
) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
if (state is PlanCreateLoadedState) {
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/plans/plan_edit_screen/models/plan_edit_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,16 +26,14 @@ class PlanEditBloc extends Bloc<PlanEditEvent, PlanEditState> {
|
||||
Emitter<PlanEditState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final String? planID = state.planModelObj?.planID;
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/plans/show/$planID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/plans/plan_select_screen/models/plan_select_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
@@ -27,9 +27,7 @@ class PlanSelectBloc extends Bloc<PlanSelectEvent, PlanSelectState> {
|
||||
Emitter<PlanSelectState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final response = await http.get(
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/plans/plan_show_screen/models/plan_show_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,16 +26,14 @@ class PlanBloc extends Bloc<PlanEvent, PlanState> {
|
||||
Emitter<PlanState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final String? planID = state.planModelObj?.planID;
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/plans/show/$planID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -62,16 +60,14 @@ class PlanBloc extends Bloc<PlanEvent, PlanState> {
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteEntry(DeleteEntry event, Emitter<PlanState> emit) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final int id = event.id;
|
||||
final response = await http.post(
|
||||
Uri.parse(baseUrl + '/api/plans/delete/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/profile/my_profile_screen/models/my_profile_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
@@ -28,9 +28,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
Emitter<MyProfileState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
//final token =
|
||||
@@ -38,7 +36,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/profile/index'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -48,10 +46,6 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
data.containsKey('userDetails') &&
|
||||
data.containsKey('chartPoints') &&
|
||||
data.containsKey('circumferences')) {
|
||||
final avatarBox = await Hive.openBox('avatar');
|
||||
final avatar = data['user']['profile_photo_path'];
|
||||
print(avatar);
|
||||
avatarBox.put('avatar', avatar);
|
||||
if (state is MyProfileLoadedState) {
|
||||
var currentState = state as MyProfileLoadedState;
|
||||
var plans = []
|
||||
@@ -69,7 +63,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
user: data['user'],
|
||||
userDetails: data['userDetails'],
|
||||
plans: plans,
|
||||
token: token,
|
||||
token: await TokenStorage.getTokenFromStorage(),
|
||||
chestCircumferenceController: TextEditingController(),
|
||||
waistCircumferenceController: TextEditingController(),
|
||||
hipCircumferenceController: TextEditingController(),
|
||||
@@ -172,7 +166,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
user: data['user'],
|
||||
userDetails: data['userDetails'],
|
||||
plans: plans,
|
||||
token: token,
|
||||
token: await TokenStorage.getTokenFromStorage(),
|
||||
chestCircumferenceController: TextEditingController(),
|
||||
waistCircumferenceController: TextEditingController(),
|
||||
hipCircumferenceController: TextEditingController(),
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/recipe/recipe_edit_screen/models/recipe_edit_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -29,16 +29,14 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
Emitter<RecipeEditState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final String? recipeID = state.recipeModelObj?.recipeID;
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/recipes/show/$recipeID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -79,7 +77,7 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
|
||||
emit(
|
||||
RecipeEditLoadedState(
|
||||
token: token,
|
||||
token: await TokenStorage.getTokenFromStorage(),
|
||||
recipe: data,
|
||||
title: TextEditingController(text: data['title']),
|
||||
description: TextEditingController(text: data['description']),
|
||||
@@ -191,17 +189,14 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
}
|
||||
|
||||
_fetchTags(int id) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/recipes/getTags/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
final data = jsonDecode(response.body);
|
||||
@@ -210,9 +205,7 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
||||
|
||||
FutureOr<void> _reloadScreen(RecipeEditEvent? event, Emitter<RecipeEditState> emit) async {
|
||||
print('Reloading..');
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
if (state is RecipeEditLoadedState) {
|
||||
|
||||
@@ -2,12 +2,12 @@ import 'dart:async';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
import 'package:eatvio_app/presentation/recipe/recipe_select_screen/models/recipe_select_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,9 +26,7 @@ class RecipeSelectBloc extends Bloc<RecipeSelectEvent, RecipeSelectState> {
|
||||
Emitter<RecipeSelectState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final response = await sl<Dio>().get(baseUrl + '/api/recipes/index');
|
||||
|
||||
@@ -2,12 +2,12 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/feed/blog_post_screen/models/comment_model.dart';
|
||||
import 'package:eatvio_app/presentation/recipe/recipe_show_screen/models/recipe_show_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
@@ -29,16 +29,14 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
||||
Emitter<RecipeState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final String? recipeID = state.recipeModelObj?.recipeID;
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/recipes/show/$recipeID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -60,7 +58,7 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
||||
} else {
|
||||
emit(
|
||||
RecipeLoadedState(
|
||||
token: token,
|
||||
token: await TokenStorage.getTokenFromStorage(),
|
||||
recipe: data,
|
||||
steps: data['steps'],
|
||||
author: await _fetchAuthor(data['id']),
|
||||
@@ -85,16 +83,14 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteEntry(DeleteEntry event, Emitter<RecipeState> emit) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final int id = event.id;
|
||||
final response = await http.post(
|
||||
Uri.parse(baseUrl + '/api/recipes/delete/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -122,17 +118,14 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
||||
}
|
||||
|
||||
_fetchAuthor(int id) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/recipes/getAuthor/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
final data = jsonDecode(response.body);
|
||||
@@ -140,15 +133,13 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
||||
}
|
||||
|
||||
Future<List> _fetchComments(int id) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/recipes/getComments/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
final data = jsonDecode(response.body);
|
||||
@@ -156,17 +147,14 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
||||
}
|
||||
|
||||
_fetchTags(int id) async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/recipes/getTags/$id'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
final data = jsonDecode(response.body);
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/users/subscribers_screen/models/subscribers_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,15 +26,13 @@ class SubscribersBloc extends Bloc<SubscribersEvent, SubscribersState> {
|
||||
Emitter<SubscribersState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/profile/subscribers'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
print('Got response');
|
||||
|
||||
Reference in New Issue
Block a user