import 'package:get/get.dart'; import 'package:sk_base_mobile/apis/api.dart'; import 'package:sk_base_mobile/models/resource.model.dart'; import 'package:sk_base_mobile/store/auth.store.dart'; import 'package:sk_base_mobile/util/logger_util.dart'; class ResourceService extends GetxService { static ResourceService get to => Get.find(); Future init() async { if (AuthStore.to.userInfo.value.id == null) return this; await getResources(); return this; } RxList resources = RxList([]); Future getResources() async { try { final response = await Api.getResources(); final appResources = (response.data as List) .map((item) => ResourceModel.fromJson(item)) .toList() .firstWhereOrNull( (element) => element.name == 'App', ); if (appResources != null) { resources.assignAll(appResources.children); } } catch (e) { LoggerUtil().error('getResources error: $e'); } } // List getDictItemsByCode(String code) { // return dictTypes.firstWhereOrNull((item) => item.code == code)?.dictItems ?? // []; // } }