rewards_repository.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/rewards_index_entity.dart';
  3. import 'package:domain/entity/server_time.dart';
  4. import 'package:plugin_platform/platform_export.dart';
  5. import 'package:plugin_platform/http/dio_engine.dart';
  6. import 'package:plugin_platform/http/http_result.dart';
  7. import 'package:riverpod_annotation/riverpod_annotation.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:shared/utils/util.dart';
  10. import 'package:flutter_riverpod/flutter_riverpod.dart';
  11. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  12. import './rewards_state.dart';
  13. part 'rewards_repository.g.dart';
  14. @Riverpod(keepAlive: true)
  15. RewardsRepository rewardsRepository(Ref ref) {
  16. final dioEngine = ref.watch(dioEngineProvider);
  17. return RewardsRepository(dioEngine: dioEngine);
  18. }
  19. /*
  20. * 数据仓库
  21. */
  22. class RewardsRepository {
  23. DioEngine dioEngine;
  24. RewardsRepository({required this.dioEngine});
  25. Future<HttpResult<Object>> fetchPropertyNewsList(
  26. Map<String, dynamic>? data, {
  27. CancelToken? cancelToken,
  28. }) async {
  29. Map<String, dynamic> params = {};
  30. params = data!;
  31. Map<String, String> headers = {};
  32. headers["Content-Type"] = "application/x-www-form-urlencoded";
  33. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  34. final result = await dioEngine.requestNetResult(
  35. // ApiConstants.apiServerTime, // api 地址
  36. '/api/v1/user/reward/index', // api 地址
  37. params: params,
  38. headers: headers,
  39. method: HttpMethod.GET,
  40. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  41. networkDebounce: true, //是否防抖防止重复请求
  42. cancelToken: cancelToken,
  43. );
  44. Log.d("------请求返回的result--$result--------");
  45. //根据返回的结果,封装原始数据为Bean/Entity对象
  46. if (result.isSuccess) {
  47. //重新赋值data或list
  48. final json = result.getDataJson();
  49. var data = RewardsIndexEntity.fromJson(json!);
  50. Log.d("------data--$data--------");
  51. //重新赋值data或list
  52. return result.convert<RewardsIndexEntity>(data: data);
  53. }
  54. return result.convert();
  55. }
  56. }