fix : auth middleware
This commit is contained in:
@@ -13,6 +13,7 @@ export 'package:geolocator/geolocator.dart';
|
||||
export 'package:get/get.dart';
|
||||
//di
|
||||
export 'package:get_it/get_it.dart';
|
||||
export 'injection/di.dart';
|
||||
|
||||
//local storage
|
||||
export 'package:hive_ce_flutter/hive_flutter.dart';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive_ce_flutter/hive_flutter.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'i_local_storage.dart';
|
||||
|
||||
@@ -33,36 +33,42 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<T?> read<T>({required String boxName,required String key}) async {
|
||||
Box? box = await getBox(boxName);
|
||||
return box.get(key) as T?;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Future<void> add({required String boxName,required dynamic value}) async {
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.add(value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addAll({required String boxName,required Iterable values}) async {
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.addAll(values);
|
||||
}
|
||||
|
||||
Future<Box<T>> getBox<T>(String boxName) async {
|
||||
final box = _boxes[boxName];
|
||||
if (box is Box<T>) {
|
||||
return box;
|
||||
} else {
|
||||
throw Exception('Box $boxName is not of expected type $T');
|
||||
T? read<T>({required String boxName, required String key}) {
|
||||
try {
|
||||
Box? box = getBox(boxName);
|
||||
return box?.get(key) as T?;
|
||||
} on Exception catch (e) {
|
||||
eLog(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear(String boxName) async{
|
||||
Future<void> add({required String boxName, required dynamic value}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.add(value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addAll({
|
||||
required String boxName,
|
||||
required Iterable values,
|
||||
}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.addAll(values);
|
||||
}
|
||||
|
||||
Box<T>? getBox<T>(String boxName) {
|
||||
final box = _boxes[boxName];
|
||||
if (box is Box<T>) {
|
||||
return box;
|
||||
} else {
|
||||
throw Exception('Box $boxName is not of exist');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear(String boxName) async {
|
||||
await _boxes[boxName]?.clear();
|
||||
}
|
||||
|
||||
@@ -74,8 +80,8 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
required String boxName,
|
||||
required String key,
|
||||
}) async {
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.delete(key);
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.delete(key);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -83,15 +89,15 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
required String boxName,
|
||||
required String key,
|
||||
required value,
|
||||
}) async{
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.put(key, value);
|
||||
}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.put(key, value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveAll({required String boxName, required Map entries}) async{
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.putAll(entries);
|
||||
Future<void> saveAll({required String boxName, required Map entries}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.putAll(entries);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -99,8 +105,8 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
required String boxName,
|
||||
required int index,
|
||||
required value,
|
||||
}) async{
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.putAt(index, value);
|
||||
}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.putAt(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ abstract class ILocalStorage<E> {
|
||||
String? collection,
|
||||
});
|
||||
|
||||
Future<T?> read<T>({required String boxName, required String key});
|
||||
T? read<T>({required String boxName, required String key});
|
||||
|
||||
Future<void> deleteValue({required String boxName, required String key});
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ final diCore = GetIt.instance;
|
||||
Future<void> setupAllProvider() async {
|
||||
await _setUpLogger();
|
||||
await _setupLocalStorage();
|
||||
await _setupRemote();
|
||||
await diCore.allReady();
|
||||
}
|
||||
|
||||
@@ -21,5 +22,5 @@ Future<void> _setupLocalStorage() async {
|
||||
|
||||
|
||||
Future<void> _setupRemote() async {
|
||||
diCore.registerSingleton<HiveLocalStorage>(HiveLocalStorage());
|
||||
// diCore.registerSingleton<HiveLocalStorage>(HiveLocalStorage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user