payment_repository.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'dart:typed_data';
  2. import 'package:domain/entity/payment_page_entity.dart';
  3. import 'package:plugin_platform/platform_export.dart';
  4. import 'package:plugin_platform/http/dio_engine.dart';
  5. import 'package:plugin_platform/http/http_result.dart';
  6. import 'package:riverpod_annotation/riverpod_annotation.dart';
  7. import '../constants/api_constants.dart';
  8. import 'package:flutter_riverpod/flutter_riverpod.dart';
  9. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  10. part 'payment_repository.g.dart';
  11. @Riverpod(keepAlive: true)
  12. PaymentRepository paymentRepository(Ref ref) {
  13. final dioEngine = ref.watch(dioEngineProvider);
  14. return PaymentRepository(dioEngine: dioEngine);
  15. }
  16. /*
  17. * 支付模块的数据仓库
  18. */
  19. class PaymentRepository {
  20. DioEngine dioEngine;
  21. PaymentRepository({required this.dioEngine});
  22. /// 获取支付列表
  23. Future<HttpResult<PaymentPageEntity>> fetchPaymentList({
  24. required String type,
  25. required int curPage,
  26. CancelToken? cancelToken,
  27. }) async {
  28. Map<String, String> params = {};
  29. params['type'] = type;
  30. params['page'] = curPage.toString();
  31. params['limit'] = "10";
  32. final result = await dioEngine.requestNetResult(
  33. ApiConstants.apiPaymentList,
  34. params: params,
  35. method: HttpMethod.GET,
  36. cancelToken: cancelToken,
  37. );
  38. if (result.isSuccess) {
  39. final json = result.getDataJson();
  40. var data = PaymentPageEntity.fromJson(json!);
  41. return result.convert<PaymentPageEntity>(data: data);
  42. }
  43. return result.convert();
  44. }
  45. }