game_info_model.dart 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import 'dart:math';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:sport/bean/game.dart';
  4. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  5. import 'package:sport/services/api/inject_api.dart';
  6. class GameInfoModel extends ChangeNotifier with InjectApi {
  7. /// 登录
  8. Future<GameInfoData> getGameInfo() async {
  9. dynamic data = await api.getGameAll();
  10. notifyListeners();
  11. return data;
  12. }
  13. }
  14. class CommentListModel extends ViewStateRefreshListModel with InjectApi {
  15. String id;
  16. String by = "like_count";
  17. CommentListModel(this.id, {this.by = "like_count"});
  18. int total = 0;
  19. @override
  20. Future<List> loadData({int pageNum = 1}) async {
  21. var page = await api.getPostComments(id, page: max(1, pageNum), sortBy: by);
  22. total = page.pageResult.count;
  23. return handlePage(page);
  24. }
  25. sortBy(String name) {
  26. if (name == "点赞最多") {
  27. by = "like_count";
  28. } else if (name == "最新评论") {
  29. by = "created_at";
  30. }
  31. initData();
  32. }
  33. }