diff --git a/packages/core/lib/infrastructure/local/hive_local_storage.dart b/packages/core/lib/infrastructure/local/hive_local_storage.dart index fb3142e..2ccfe27 100644 --- a/packages/core/lib/infrastructure/local/hive_local_storage.dart +++ b/packages/core/lib/infrastructure/local/hive_local_storage.dart @@ -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( - boxName, - encryptionCipher: encryptionCipher, - crashRecovery: crashRecovery, - ); + try { + var exist = await Hive.boxExists(boxName); + if (!exist || !Hive.isBoxOpen(boxName)) { + await Hive.openBox( + boxName, + encryptionCipher: encryptionCipher, + crashRecovery: crashRecovery, + ); + } + } catch (e) { + eLog(e); + rethrow; } } @override T? read({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? readBox({required String boxName}) { try { + if (!Hive.isBoxOpen(boxName)) { + return null; + } Box? box = getBox(boxName); return box?.values.cast().toList(); - } on Exception catch (e) { + } catch (e) { eLog(e); return null; } @@ -54,50 +65,141 @@ class HiveLocalStorage implements ILocalStorage { @override Future add({required String boxName, required dynamic value}) async { - Box? box = getBox(boxName); - await box?.add(value); + try { + if (!Hive.isBoxOpen(boxName)) { + await openBox(boxName); + } + Box? box = getBox(boxName); + await box?.add(value); + } catch (e) { + eLog(e); + rethrow; + } } @override - Future addAll({required String boxName, required Iterable values}) async { - Box? box = getBox(boxName); - await box?.addAll(values); + Future addAll({ + required String boxName, + required Iterable values, + }) async { + try { + if (!Hive.isBoxOpen(boxName)) { + await openBox(boxName); + } + Box? box = getBox(boxName); + await box?.addAll(values); + } catch (e) { + eLog(e); + rethrow; + } } Box? getBox(String boxName) { - final box = Hive.box(boxName); - return box; + try { + if (!Hive.isBoxOpen(boxName)) { + return null; + } + final box = Hive.box(boxName); + return box; + } catch (e) { + eLog(e); + return null; + } } @override Future 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 close(String boxName) async => await Hive.box(boxName).close(); - - @override - Future deleteValue({required String boxName, required String key}) async { - Box? box = getBox(boxName); - await box?.delete(key); + Future close(String boxName) async { + try { + if (!Hive.isBoxOpen(boxName)) { + return; + } + await Hive.box(boxName).close(); + } catch (e) { + eLog(e); + rethrow; + } } @override - Future save({required String boxName, required String key, required value}) async { - Box? box = getBox(boxName); - await box?.put(key, value); + Future deleteValue({ + required String boxName, + required String key, + }) async { + try { + if (!Hive.isBoxOpen(boxName)) { + return; + } + Box? box = getBox(boxName); + await box?.delete(key); + } catch (e) { + eLog(e); + rethrow; + } } @override - Future saveAll({required String boxName, required Map entries}) async { - Box? box = getBox(boxName); - await box?.putAll(entries); + Future save({ + required String boxName, + required String key, + required value, + }) async { + try { + if (!Hive.isBoxOpen(boxName)) { + await openBox(boxName); + } + Box? box = getBox(boxName); + await box?.put(key, value); + } catch (e) { + eLog(e); + rethrow; + } } @override - Future saveAt({required String boxName, required int index, required value}) async { - Box? box = getBox(boxName); - await box?.putAt(index, value); + Future saveAll({ + required String boxName, + required Map entries, + }) async { + try { + if (!Hive.isBoxOpen(boxName)) { + await openBox(boxName); + } + Box? box = getBox(boxName); + await box?.putAll(entries); + } catch (e) { + eLog(e); + rethrow; + } + } + + @override + Future saveAt({ + required String boxName, + required int index, + required value, + }) async { + try { + if (!Hive.isBoxOpen(boxName)) { + await openBox(boxName); + } + Box? box = getBox(boxName); + await box?.putAt(index, value); + } catch (e) { + eLog(e); + rethrow; + } } } diff --git a/packages/core/lib/infrastructure/remote/dio_form_data.dart b/packages/core/lib/infrastructure/remote/dio_form_data.dart index 8e74832..4a91910 100644 --- a/packages/core/lib/infrastructure/remote/dio_form_data.dart +++ b/packages/core/lib/infrastructure/remote/dio_form_data.dart @@ -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 addFile(String field, Uint8List bytes, String filename) async { + _formData.files.add( + MapEntry(field, MultipartFile.fromBytes(bytes, filename: filename)), + ); } @override diff --git a/packages/core/lib/infrastructure/remote/dio_remote.dart b/packages/core/lib/infrastructure/remote/dio_remote.dart index 184595a..c1d6bd7 100644 --- a/packages/core/lib/infrastructure/remote/dio_remote.dart +++ b/packages/core/lib/infrastructure/remote/dio_remote.dart @@ -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 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 ? fromJson(rawData) : null; + final parsedData = rawData is Map + ? fromJson(rawData) + : null; response.data = parsedData; return DioResponse(response); } @@ -136,7 +154,9 @@ class DioRemote implements IHttpClient { ); if (fromJson != null) { final rawData = response.data; - final parsedData = rawData is Map ? fromJson(rawData) : null; + final parsedData = rawData is Map + ? fromJson(rawData) + : null; response.data = parsedData; return DioResponse(response); } diff --git a/packages/core/lib/infrastructure/remote/interfaces/i_form_data.dart b/packages/core/lib/infrastructure/remote/interfaces/i_form_data.dart index ddbda85..449a129 100644 --- a/packages/core/lib/infrastructure/remote/interfaces/i_form_data.dart +++ b/packages/core/lib/infrastructure/remote/interfaces/i_form_data.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; abstract class IFormData{ - void addFile(String field, Uint8List bytes, String filename); + Future addFile(String field, Uint8List bytes, String filename); void addField(String key, String value); } \ No newline at end of file diff --git a/packages/core/lib/injection/di.dart b/packages/core/lib/injection/di.dart index 1bc9558..65308b8 100644 --- a/packages/core/lib/injection/di.dart +++ b/packages/core/lib/injection/di.dart @@ -11,12 +11,11 @@ Future setupAllCoreProvider() async { diCore.registerSingleton(ImagePicker()); //max 500MB Map Cashing -// await FMTCObjectBoxBackend().initialise(); + // await FMTCObjectBoxBackend().initialise(); await diCore.allReady(); } - Future _setupLocalStorage() async { var localStorage = diCore.registerSingleton(HiveLocalStorage()); await localStorage.init(); diff --git a/packages/core/lib/presentation/common/app_fonts.dart b/packages/core/lib/presentation/common/app_fonts.dart index cd31938..fdeda8d 100644 --- a/packages/core/lib/presentation/common/app_fonts.dart +++ b/packages/core/lib/presentation/common/app_fonts.dart @@ -1,11 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -class AppFonts { - AppFonts._(); // Private constructor to prevent instantiation +import 'fonts.gen.dart'; - // --- Font Families --- - static const String yekan = 'yekan'; +class AppFonts { + AppFonts._(); // --- Font Weights --- static const FontWeight regular = FontWeight.w400; @@ -13,202 +12,199 @@ class AppFonts { static const double _height = 1.20; static TextStyle yekan61 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 61.sp, height: _height, ); static TextStyle yekan49 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 48.sp, height: _height, ); static TextStyle yekan39 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 39.sp, height: _height, ); static TextStyle yekan31 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 31.sp, height: _height, ); static TextStyle yekan25 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 25.sp, height: _height, ); static TextStyle yekan24 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 24.sp, height: _height, ); static TextStyle yekan20 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 20.sp, height: _height, ); static TextStyle yekan18 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 18.sp, height: _height, ); static TextStyle yekan16 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 16.sp, height: _height, ); static TextStyle yekan14 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 13.sp, height: _height, ); - - static TextStyle yekan13 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 13.sp, height: _height, ); - static TextStyle yekan12 = TextStyle( - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 12.sp, height: _height, ); - - static TextStyle yekan10 = TextStyle( + static TextStyle yekan10 = TextStyle( // Rounded from 10.24 - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 10.sp, height: _height, ); - - static TextStyle yekan8= TextStyle( + static TextStyle yekan8 = TextStyle( // Rounded from 10.24 - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: regular, fontSize: 8.sp, height: _height, ); - static TextStyle yekan61Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan61Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 61.sp, height: _height, ); - static TextStyle yekan49Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan49Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 48.sp, height: _height, ); - static TextStyle yekan39Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan39Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 39.sp, height: _height, ); - static TextStyle yekan31Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan31Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 31.sp, height: _height, ); - static TextStyle yekan25Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan25Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 25.sp, height: _height, ); - static TextStyle yekan24Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan24Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 24.sp, height: _height, ); - static TextStyle yekan20Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan20Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 20.sp, height: _height, ); - - static TextStyle yekan18Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan18Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 18.sp, height: _height, ); - - static TextStyle yekan16Bold = TextStyle( + static TextStyle yekan16Bold = TextStyle( // Base size bold - fontFamily: yekan, + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 16.sp, height: _height, ); - - static TextStyle yekan14Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan14Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 13.sp, height: _height, ); - - static TextStyle yekan13Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan13Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 13.sp, height: _height, ); - static TextStyle yekan12Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan12Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 12.sp, height: _height, ); + static TextStyle yekan11Bold = TextStyle( + fontFamily: FontFamily.yekan, + fontWeight: bold, // Use bold weight + fontSize: 12.sp, + height: _height, + ); - static TextStyle yekan10Bold = TextStyle( - fontFamily: yekan, + static TextStyle yekan10Bold = TextStyle( + fontFamily: FontFamily.yekan, fontWeight: bold, // Use bold weight fontSize: 10.sp, height: _height, diff --git a/pubspec.lock b/pubspec.lock index e9b5628..1038136 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1354,7 +1354,7 @@ packages: path: "packages/chicken" relative: true source: path - version: "1.3.18" + version: "1.3.20" rasadyar_core: dependency: "direct main" description: