mobile_skt/lib/store/resource.store.dart

33 lines
1008 B
Dart

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<ResourceService> init() async {
if (AuthStore.to.userInfo.value.id == null) return this;
await getResources();
return this;
}
RxList<ResourceModel> resources = RxList([]);
Future<void> getResources() async {
try {
final response = await Api.getResources();
resources.value = (response.data as List)
.map((item) => ResourceModel.fromJson(item))
.toList();
} catch (e) {
LoggerUtil().error('getResources error: $e');
}
}
// List<DictItemModel> getDictItemsByCode(String code) {
// return dictTypes.firstWhereOrNull((item) => item.code == code)?.dictItems ??
// [];
// }
}