facility_detail_view_model.dart 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import 'package:domain/repository/facility_repository.dart';
  2. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  3. import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
  4. import 'package:riverpod_annotation/riverpod_annotation.dart';
  5. import 'facility_detail_state.dart';
  6. part 'facility_detail_view_model.g.dart';
  7. @riverpod
  8. class FacilityDetailViewModel extends _$FacilityDetailViewModel with DioCancelableMixin{
  9. late final FacilityRepository _facilityRepository;
  10. @override
  11. FacilityDetailState build() {
  12. _facilityRepository = ref.read(facilityRepositoryProvider);
  13. final state = FacilityDetailState();
  14. registerCancellation();
  15. return state;
  16. }
  17. /// 获取详情
  18. Future fetchFacilityDetail(String? bookingId) async {
  19. final result = await _facilityRepository.fetchFacilityBookingDetail(id: bookingId, cancelToken: cancelToken);
  20. // 处理数据
  21. if (result.isSuccess) {
  22. state = state.copyWith(detail: result.data);
  23. } else {
  24. ToastEngine.show(result.errorMsg ?? "UnKnow Error");
  25. }
  26. }
  27. }