feat: update font family references and improve error handling in local storage

This commit is contained in:
2025-11-26 09:59:18 +03:30
parent b5be900182
commit 91e8d73030
7 changed files with 216 additions and 100 deletions

View File

@@ -20,22 +20,30 @@ class HiveLocalStorage implements ILocalStorage {
Uint8List? bytes,
String? collection,
}) async {
var exist = await Hive.boxExists(boxName);
if (!exist || !Hive.isBoxOpen(boxName)) {
await Hive.openBox<T>(
boxName,
encryptionCipher: encryptionCipher,
crashRecovery: crashRecovery,
);
try {
var exist = await Hive.boxExists(boxName);
if (!exist || !Hive.isBoxOpen(boxName)) {
await Hive.openBox<T>(
boxName,
encryptionCipher: encryptionCipher,
crashRecovery: crashRecovery,
);
}
} catch (e) {
eLog(e);
rethrow;
}
}
@override
T? read<T>({required String boxName, required String key}) {
try {
if (!Hive.isBoxOpen(boxName)) {
return null;
}
Box? box = getBox(boxName);
return box?.get(key) as T?;
} on Exception catch (e) {
} catch (e) {
eLog(e);
return null;
}
@@ -44,9 +52,12 @@ class HiveLocalStorage implements ILocalStorage {
@override
List<T>? readBox<T>({required String boxName}) {
try {
if (!Hive.isBoxOpen(boxName)) {
return null;
}
Box? box = getBox<T>(boxName);
return box?.values.cast<T>().toList();
} on Exception catch (e) {
} catch (e) {
eLog(e);
return null;
}
@@ -54,50 +65,141 @@ class HiveLocalStorage implements ILocalStorage {
@override
Future<void> add<T>({required String boxName, required dynamic value}) async {
Box<dynamic>? box = getBox<T>(boxName);
await box?.add(value);
try {
if (!Hive.isBoxOpen(boxName)) {
await openBox<T>(boxName);
}
Box<dynamic>? box = getBox<T>(boxName);
await box?.add(value);
} catch (e) {
eLog(e);
rethrow;
}
}
@override
Future<void> addAll<T>({required String boxName, required Iterable values}) async {
Box<dynamic>? box = getBox<T>(boxName);
await box?.addAll(values);
Future<void> addAll<T>({
required String boxName,
required Iterable values,
}) async {
try {
if (!Hive.isBoxOpen(boxName)) {
await openBox<T>(boxName);
}
Box<dynamic>? box = getBox<T>(boxName);
await box?.addAll(values);
} catch (e) {
eLog(e);
rethrow;
}
}
Box<T>? getBox<T>(String boxName) {
final box = Hive.box<T>(boxName);
return box;
try {
if (!Hive.isBoxOpen(boxName)) {
return null;
}
final box = Hive.box<T>(boxName);
return box;
} catch (e) {
eLog(e);
return null;
}
}
@override
Future<void> clear(String boxName) async {
await Hive.box(boxName).clear();
try {
if (!Hive.isBoxOpen(boxName)) {
return;
}
await Hive.box(boxName).clear();
} catch (e) {
eLog(e);
rethrow;
}
}
@override
Future<void> close(String boxName) async => await Hive.box(boxName).close();
@override
Future<void> deleteValue<T>({required String boxName, required String key}) async {
Box<dynamic>? box = getBox<T>(boxName);
await box?.delete(key);
Future<void> close(String boxName) async {
try {
if (!Hive.isBoxOpen(boxName)) {
return;
}
await Hive.box(boxName).close();
} catch (e) {
eLog(e);
rethrow;
}
}
@override
Future<void> save<T>({required String boxName, required String key, required value}) async {
Box<dynamic>? box = getBox<T>(boxName);
await box?.put(key, value);
Future<void> deleteValue<T>({
required String boxName,
required String key,
}) async {
try {
if (!Hive.isBoxOpen(boxName)) {
return;
}
Box<dynamic>? box = getBox<T>(boxName);
await box?.delete(key);
} catch (e) {
eLog(e);
rethrow;
}
}
@override
Future<void> saveAll<T>({required String boxName, required Map entries}) async {
Box<dynamic>? box = getBox<T>(boxName);
await box?.putAll(entries);
Future<void> save<T>({
required String boxName,
required String key,
required value,
}) async {
try {
if (!Hive.isBoxOpen(boxName)) {
await openBox<T>(boxName);
}
Box<dynamic>? box = getBox<T>(boxName);
await box?.put(key, value);
} catch (e) {
eLog(e);
rethrow;
}
}
@override
Future<void> saveAt<T>({required String boxName, required int index, required value}) async {
Box<dynamic>? box = getBox<T>(boxName);
await box?.putAt(index, value);
Future<void> saveAll<T>({
required String boxName,
required Map entries,
}) async {
try {
if (!Hive.isBoxOpen(boxName)) {
await openBox<T>(boxName);
}
Box<dynamic>? box = getBox<T>(boxName);
await box?.putAll(entries);
} catch (e) {
eLog(e);
rethrow;
}
}
@override
Future<void> saveAt<T>({
required String boxName,
required int index,
required value,
}) async {
try {
if (!Hive.isBoxOpen(boxName)) {
await openBox<T>(boxName);
}
Box<dynamic>? box = getBox<T>(boxName);
await box?.putAt(index, value);
} catch (e) {
eLog(e);
rethrow;
}
}
}

View File

@@ -7,11 +7,10 @@ class DioFormData implements IFormData {
final FormData _formData = FormData();
@override
void addFile(String field, Uint8List bytes, String filename) {
_formData.files.add(MapEntry(
field,
MultipartFile.fromBytes(bytes, filename: filename),
));
Future<void> addFile(String field, Uint8List bytes, String filename) async {
_formData.files.add(
MapEntry(field, MultipartFile.fromBytes(bytes, filename: filename)),
);
}
@override

View File

@@ -5,12 +5,28 @@ class DioRemote implements IHttpClient {
String? baseUrl;
late Dio dio;
AppInterceptor? interceptors;
Duration? connectTimeout;
Duration? receiveTimeout;
Duration? sendTimeout;
DioRemote({this.baseUrl, this.interceptors});
DioRemote({
this.baseUrl,
this.interceptors,
this.connectTimeout,
this.receiveTimeout,
this.sendTimeout,
});
@override
Future<void> init() async {
dio = Dio(BaseOptions(baseUrl: baseUrl ?? ''));
dio = Dio(
BaseOptions(
baseUrl: baseUrl ?? '',
connectTimeout: connectTimeout ?? const Duration(seconds: 30),
receiveTimeout: receiveTimeout ?? const Duration(seconds: 30),
sendTimeout: sendTimeout ?? const Duration(seconds: 30),
),
);
if (interceptors != null) {
interceptors!.dio = dio;
dio.interceptors.add(interceptors!);
@@ -84,7 +100,9 @@ class DioRemote implements IHttpClient {
if (fromJson != null) {
final rawData = response.data;
final parsedData = rawData is Map<String, dynamic> ? fromJson(rawData) : null;
final parsedData = rawData is Map<String, dynamic>
? fromJson(rawData)
: null;
response.data = parsedData;
return DioResponse<T>(response);
}
@@ -136,7 +154,9 @@ class DioRemote implements IHttpClient {
);
if (fromJson != null) {
final rawData = response.data;
final parsedData = rawData is Map<String, dynamic> ? fromJson(rawData) : null;
final parsedData = rawData is Map<String, dynamic>
? fromJson(rawData)
: null;
response.data = parsedData;
return DioResponse<T>(response);
}

View File

@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
abstract class IFormData{
void addFile(String field, Uint8List bytes, String filename);
Future<void> addFile(String field, Uint8List bytes, String filename);
void addField(String key, String value);
}