user_activity_provider.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import 'package:flutter_riverpod/flutter_riverpod.dart';
  2. import 'package:news_app/provider/user_favorite_provider.dart';
  3. import '../constant/api_const.dart';
  4. import '../http/http_util.dart';
  5. import '../http/model_parser.dart';
  6. /// @author: bo.zeng
  7. /// @email: cnhbwds@gmail.com
  8. /// @date: 2025 2025/4/22 16:03
  9. /// @description:
  10. class UserActivityProvider extends Notifier<UserActivity> {
  11. @override
  12. UserActivity build() {
  13. return UserActivity();
  14. }
  15. //type 1.通过。2.不通过
  16. Future<void> fetchUserActivity({
  17. required int type,
  18. required int pageNum,
  19. }) async {
  20. final jsonData = await HttpUtil().get(
  21. apiMemberActivities,
  22. queryParameters: {
  23. "type": type,
  24. "pageSize": 10,
  25. "pageNum": pageNum.toString(),
  26. },
  27. );
  28. final response = ModelParser.parseObject<UserActivity>(
  29. jsonData,
  30. UserActivity.fromJson,
  31. );
  32. state.total = response.total;
  33. if (pageNum == 0) {
  34. state = response;
  35. } else {
  36. //把新的列表添加到旧的列表中
  37. state = UserActivity(
  38. total: response.total,
  39. rows: [...state.rows ?? [], ...response.rows ?? []],
  40. );
  41. }
  42. }
  43. }