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
/*
* @author lsy
* @date 2019-10-15
**/
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:gmalpha_flutter/commonModel/GMBase.dart';
import 'package:gmalpha_flutter/commonModel/toast/toast.dart';
import 'package:gmalpha_flutter/commonModel/util/IsolateUtil.dart';
import 'package:gmalpha_flutter/userModel/page/country/CountryJson.dart';
import 'package:gmalpha_flutter/userModel/service/UserRepository.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/CountryBean.dart';
class CountryModel extends BaseModel {
LiveData<CountryBean> liveData = new LiveData();
final String refer;
String selectCity;
CountryModel(this.refer);
getCountries(BuildContext context) {
// getStaticCountry().then((value) {
// if (value != null) {
// liveData.notifyView(value);
// } else {
// getCountryFromNet(context);
// }
// }).catchError((error) {
// Toast.debugShow(context, error);
// print(error);
// });
paseJson().then((value) {
if (value != null) {
liveData.notifyView(value);
}
});
}
getCountryFromNet(BuildContext context) {
UserRepository.getInstance().getCountries().listen((value) {
liveData.notifyView(value);
}).onError((error) {
Toast.debugShow(context, error);
print(error);
});
}
Future paseJson() async {
return await compute(pase, 1);
}
@override
void dispose() {
liveData.dispost();
}
}
CountryBean pase(int a) {
return CountryBean.fromJson(json.decode(STATIC_COUNTRY_JSON));
}