78 lines
2.4 KiB
Dart
78 lines
2.4 KiB
Dart
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
|
|
import 'package:rasadyar_chicken/data/di/chicken_di.dart';
|
|
import 'package:rasadyar_chicken/presentation/routes/routes.dart';
|
|
import 'package:rasadyar_core/core.dart';
|
|
import 'package:rasadyar_core/data/model/local/target_page/target_page.dart';
|
|
import 'package:rasadyar_inspection/injection/inspection_di.dart';
|
|
import 'package:rasadyar_inspection/inspection.dart';
|
|
import 'package:rasadyar_livestock/injection/live_stock_di.dart';
|
|
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
|
|
|
class LocalStorageService extends GetxService {
|
|
static const String _targetPageBox = 'targetPageBox';
|
|
|
|
final HiveLocalStorage _localStorage = diCore.get<HiveLocalStorage>();
|
|
|
|
|
|
Future<void> init() async {
|
|
await _localStorage.openBox<TargetPage>(_targetPageBox);
|
|
seedTargetPage();
|
|
|
|
}
|
|
|
|
Future<void> seedTargetPage() async {
|
|
var existing = getTargetPage(null);
|
|
if (existing == null) {
|
|
_localStorage.addAll<TargetPage>(
|
|
boxName: _targetPageBox,
|
|
values: <TargetPage>[
|
|
TargetPage(
|
|
route: InspectionRoutes.init,
|
|
module: Module.inspection,
|
|
functions: ["setupInspectionDI"],
|
|
),
|
|
TargetPage(
|
|
route: LiveStockRoutes.init,
|
|
module: Module.liveStocks,
|
|
functions: ["setupLiveStockDI"],
|
|
),
|
|
TargetPage(
|
|
route: ChickenRoutes.initSteward,
|
|
module: Module.chicken,
|
|
functions: ["setupChickenDI"],
|
|
),
|
|
TargetPage(route: AppPaths.moduleList),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
TargetPage? getTargetPage(Module? module) {
|
|
var res = _localStorage
|
|
.readBox<TargetPage>(boxName: _targetPageBox)
|
|
?.firstWhereOrNull((element) => element.module == module);
|
|
return res;
|
|
}
|
|
|
|
Future<void> saveTargetPage(TargetPage targetPage) async {
|
|
await _localStorage.add(boxName: _targetPageBox, value: targetPage);
|
|
}
|
|
|
|
Iterable<Future>? getFunctionsList(List<String>? functions) {
|
|
return functions?.map((e) async => getFunctionByName(e));
|
|
}
|
|
|
|
Future? getFunctionByName(String? name) {
|
|
switch (name) {
|
|
case "setupInspectionDI":
|
|
return setupInspectionDI();
|
|
case "setupLiveStockDI":
|
|
return setupLiveStockDI();
|
|
case "setupChickenDI":
|
|
return setupChickenDI();
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
}
|