12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import 'package:flutter/material.dart';
- import 'package:get_it/get_it.dart';
- import 'package:provider/provider.dart';
- import 'package:sport/application.dart';
- import 'package:sport/bean/exer_index.dart';
- import 'package:sport/bean/user.dart';
- import 'package:sport/provider/game_model.dart';
- import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
- import 'package:sport/provider/user_model.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/services/api/resp.dart';
- class SportIndexModel extends ViewStateRefreshListModel with InjectApi {
- ExerIndex? data;
- int? gameId;
- int? provinceId, cityId, districtId;
- BuildContext context;
- ValueNotifier<List<Achievement>> valueNotifier = ValueNotifier([]);
- SportIndexModel(this.context);
- @override
- Future<List> loadData({int pageNum = 0}) async {
- try {
- RespData<ExerIndex> index = await api.getExerIndex();
- data = index.data;
- if (data != null) {
- gameId = data!.games?.first.id;
- UserModel userModel = Provider.of<UserModel>(context, listen: false);
- userModel.durationTarget.value = data!.target?.duration ?? 0;
- userModel.runUserCount.value = data!.jogUserCount ?? 0;
- if (data!.newAchievements != null) {
- valueNotifier.value = data!.newAchievements ?? [];
- }
- GameModel gameModel = GetIt.I<GameModel>();
- gameModel.setGameAll(data?.games ?? []);
- buyShoesUrl = data?.buyShoesUrl;
- return [data];
- }
- } catch (e, s) {
- debugPrintStack(stackTrace: s);
- print(e);
- }
- return [];
- }
- void game(int id) {
- this.gameId = id;
- setIdle();
- switchArea();
- }
- Future area(int provinceId, int cityId, int districtId) async {
- this.provinceId = provinceId;
- this.cityId = cityId;
- this.districtId = districtId;
- setIdle();
- await switchArea();
- }
- Future switchArea() async {
- // RespData<RankInfo> resp = await api.getRankInfo(gameId.toString(),
- // provinceId: provinceId, cityId: cityId);
- // if (resp != null && resp.data != null) {
- // data.rank = resp.data;
- // setIdle();
- // }
- }
- }
|