forked from eatvio/eatvio_app
refactor(token): add token storage, remove hive
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user