1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* @author lsy
* @date 2020/6/29
**/
import 'package:flutter/material.dart';
import 'package:flutter_common/commonModel/live/BaseModel.dart';
import 'package:flutter_common/commonModel/live/LiveData.dart';
import 'package:gm_flutter/ClueModel/server/api/ClueApi.serv.dart';
import 'package:gm_flutter/ClueModel/server/entity/LevelOneFeedList.dart';
import 'package:gm_flutter/commonModel/GMBase.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
import 'package:gm_flutter/commonModel/rx/RxDispose.dart';
import 'package:gm_flutter/commonModel/util/PrintUtil.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class LevelOneModel extends BaseModel {
LiveData<double> appBarLive = LiveData();
LiveData<List<String>> rectLive = LiveData();
LiveData<List<String>> explainLive = LiveData();
LiveData<bool> showTab = LiveData();
LiveData<int> topIndexLive = new LiveData();
LiveData<double> topScrollLive = new LiveData();
LiveData<bool> loadingLive = LiveData();
RxDispose rxDispose = RxDispose();
LiveData<Pair<int, List<Cards>>> cardsLive = LiveData();
Map<int, List<Cards>> data = new Map();
List list = ["plan", "hospital", "doctor", "diary"];
List pageList = [1, 1, 1, 1];
List pageHeightList = [118, 149, 118, 118];
void refreshView(bool clear, {RefreshController refreshListener}) {
Future.delayed(Duration(seconds: 1), () {
Cards cards = Cards(
cardType: "plan",
plan: Plan(planName: "ww", minPrice: "50", maxPrice: "500"));
List<Cards> a = [
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
cards,
];
List<Cards> b = [cards];
print("INDEX ${currentIndex}");
if (currentIndex == 1) {
data[currentIndex] = b;
} else {
data[currentIndex] = a;
}
cardsLive.notifyView(Pair(ENDLOADING, data));
});
int index = currentIndex;
if (clear) {
data.clear();
pageList = [1, 1, 1, 1];
}
ClueApiImpl.getInstance()
.getLevelOneList(
DioUtil.getInstance().getDio(), 123, list[index], pageList[index])
.listen((event) {})
.addToDispose(rxDispose)
.onError((err) {
PrintUtil.printBug(err);
});
}
int currentIndex = 0;
@override
void dispose() {
showTab.dispost();
cardsLive.dispost();
appBarLive.dispost();
rectLive.dispost();
topIndexLive.dispost();
topScrollLive.dispost();
loadingLive.dispost();
}
void selectPage(int index) {
if (currentIndex == index) {
return;
}
currentIndex = index;
if (data[currentIndex] == null) {
cardsLive.notifyView(Pair(LOADING, null));
refreshView(true);
} else {
cardsLive.notifyView(Pair(ENDLOADING, data[currentIndex]));
}
}
void loadMore() {
}
}