sport_index_model.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:sport/bean/sport_index.dart';
  4. import 'package:sport/bean/user.dart';
  5. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  6. import 'package:sport/provider/user_model.dart';
  7. import 'package:sport/services/api/inject_api.dart';
  8. import 'package:sport/services/api/resp.dart';
  9. class SportIndexModel extends ViewStateRefreshListModel with InjectApi {
  10. SportIndex data;
  11. int gameId;
  12. int provinceId, cityId, districtId;
  13. BuildContext context;
  14. ValueNotifier< List<Achievement>> valueNotifier = ValueNotifier([]);
  15. SportIndexModel(this.context);
  16. @override
  17. Future<List> loadData({int pageNum}) async {
  18. data = (await api.getSportIndex()).data;
  19. if (data != null) {
  20. gameId = data.games?.first?.id;
  21. Provider.of<UserModel>(context, listen: false).durationTarget.value = data.durationTarget;
  22. // achievementList.add(data.achievement);
  23. if(data.achievement != null){
  24. valueNotifier.value = data.achievement;
  25. }
  26. return [data];
  27. } else {
  28. return [];
  29. }
  30. }
  31. void game(int id) {
  32. this.gameId = id;
  33. setIdle();
  34. switchArea();
  35. }
  36. Future area(int provinceId, int cityId, int districtId) async {
  37. this.provinceId = provinceId;
  38. this.cityId = cityId;
  39. this.districtId = districtId;
  40. setIdle();
  41. await switchArea();
  42. }
  43. Future switchArea() async {
  44. RespData<RankInfo> resp = await api.getRankInfo(gameId.toString(), provinceId: provinceId, cityId: cityId);
  45. if (resp != null && resp.data != null) {
  46. data.rank = resp.data;
  47. setIdle();
  48. }
  49. }
  50. }