feat : auth package

This commit is contained in:
2025-05-11 11:49:51 +03:30
parent 8cc4a7517c
commit 9ec761e6eb
34 changed files with 665 additions and 475 deletions

View File

@@ -0,0 +1,61 @@
import 'package:hive_ce_flutter/hive_flutter.dart';
import 'i_local_storage.dart';
class HiveLocalStorage implements ILocalStorage {
HiveLocalStorage() {
Hive.initFlutter();
}
final Map<String, Box> _boxes = {};
@override
Future init() async => await Hive.initFlutter();
@override
Future<void> openBox<T>(String boxName) async {
if (!_boxes.containsKey(boxName)) {
final box = await Hive.openBox<T>(boxName);
_boxes[boxName] = box;
}
}
@override
Future<void> delete(String boxName, String key) async {
Box<dynamic>? box = await getBox(boxName);
await box.delete(key);
}
@override
Future<T?> read<T>(String boxName, String key) async {
Box? box = await getBox(boxName);
return box.get(key) as T?;
}
@override
Future<void> save(String boxName, String key, value) async {
Box<dynamic>? box = await getBox(boxName);
await box.put(key, value);
}
@override
Future<void> add(String boxName, value) async {
Box<dynamic>? box = await getBox(boxName);
await box.add(value);
}
@override
Future<void> addAll(String boxName, 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');
}
}
}

View File

@@ -0,0 +1,11 @@
abstract class ILocalStorage<E>{
Future<void> init();
Future<void> openBox<T>(String boxName);
Future<void> save(String boxName, String key, dynamic value);
Future<T?> read<T>(String boxName, String key);
Future<void> delete(String boxName, String key);
Future<void> add(String boxName, E value);
Future<void> addAll(String boxName, Iterable<E> values);
}