sport_index_model.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:flutter/material.dart';
  2. import 'package:get_it/get_it.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:sport/application.dart';
  5. import 'package:sport/bean/exer_index.dart';
  6. import 'package:sport/bean/user.dart';
  7. import 'package:sport/provider/game_model.dart';
  8. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  9. import 'package:sport/provider/user_model.dart';
  10. import 'package:sport/services/api/inject_api.dart';
  11. import 'package:sport/services/api/resp.dart';
  12. class SportIndexModel extends ViewStateRefreshListModel with InjectApi {
  13. ExerIndex? data;
  14. int? gameId;
  15. int? provinceId, cityId, districtId;
  16. BuildContext context;
  17. ValueNotifier<List<Achievement>> valueNotifier = ValueNotifier([]);
  18. SportIndexModel(this.context);
  19. @override
  20. Future<List> loadData({int pageNum = 0}) async {
  21. try {
  22. RespData<ExerIndex> index = await api.getExerIndex();
  23. data = index.data;
  24. if (data != null) {
  25. gameId = data!.games?.first.id;
  26. UserModel userModel = Provider.of<UserModel>(context, listen: false);
  27. userModel.durationTarget.value = data!.target?.duration ?? 0;
  28. userModel.runUserCount.value = data!.jogUserCount ?? 0;
  29. if (data!.newAchievements != null) {
  30. valueNotifier.value = data!.newAchievements ?? [];
  31. }
  32. GameModel gameModel = GetIt.I<GameModel>();
  33. gameModel.setGameAll(data?.games ?? []);
  34. buyShoesUrl = data?.buyShoesUrl;
  35. return [data];
  36. }
  37. } catch (e, s) {
  38. debugPrintStack(stackTrace: s);
  39. print(e);
  40. }
  41. return [];
  42. }
  43. void game(int id) {
  44. this.gameId = id;
  45. setIdle();
  46. switchArea();
  47. }
  48. Future area(int provinceId, int cityId, int districtId) async {
  49. this.provinceId = provinceId;
  50. this.cityId = cityId;
  51. this.districtId = districtId;
  52. setIdle();
  53. await switchArea();
  54. }
  55. Future switchArea() async {
  56. // RespData<RankInfo> resp = await api.getRankInfo(gameId.toString(),
  57. // provinceId: provinceId, cityId: cityId);
  58. // if (resp != null && resp.data != null) {
  59. // data.rank = resp.data;
  60. // setIdle();
  61. // }
  62. }
  63. }