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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* @author lsy
* @date 2019-10-15
**/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/commonModel/base/BaseComponent.dart';
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/res/GMRes.dart';
import 'package:gmalpha_flutter/userModel/page/country/CountryModel.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/CountryBean.dart';
class CountryPage extends StatefulWidget {
CountryModel _model;
CountryPage(String refer) {
_model = new CountryModel(refer);
}
@override
State<StatefulWidget> createState() => CountryState(_model);
}
class CountryState extends BasePage {
CountryModel _model;
CountryState(this._model);
ScrollController _scrollController = new ScrollController();
@override
void initState() {
super.initState();
_model.getCountries(context);
_scrollController.addListener(() {
print(
"lsyy ${_scrollController.positions} OFF ${_scrollController.offset}");
});
}
@override
Widget build(BuildContext context) {
ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
return Scaffold(
appBar: baseAppBar(
centerTitle: true,
title: "选择国家",
backClick: () {
Navigator.pop(context, _model.selectCity);
}),
body: StreamBuilder<CountryBean>(
stream: _model.liveData.stream,
initialData: _model.liveData.data,
builder: (con, data) {
if (data.data == null) {
return loadingItem();
} else {
return ListView.builder(
controller: _scrollController,
itemCount: data.data?.data?.length,
itemBuilder: (con, index) {
List<Widget> list = [];
list.add(headItem(data.data.data[index].title));
for (int i = 0;
i < data.data.data[index].countries.length;
i++) {
Countries countriy = data.data.data[index].countries[i];
list.add(countryItem(countriy));
}
return Column(
children: list,
);
});
}
},
),
);
}
headItem(String head) {
return Container(
color: Color(0x22000000),
alignment: Alignment.centerLeft,
height: ScreenUtil.instance.setHeight(25),
padding: EdgeInsets.only(
left: ScreenUtil.instance.setWidth(12),
),
child: baseText(head, 15, ALColors.Color323232),
);
}
countryItem(Countries country) {
return GestureDetector(
onTap: () {
Navigator.pop(context,
{"countryId": country.id, "countryName": country.name});
},
child: Container(
alignment: Alignment.centerLeft,
height: ScreenUtil.instance.setHeight(50),
margin: EdgeInsets.only(
left: ScreenUtil.instance.setWidth(12),
),
child: baseText(country.name, 15, ALColors.Color323232),
));
}
@override
void dispose() {
super.dispose();
_scrollController.dispose();
}
@override
String pageName() {
return "country_page";
}
@override
String referrer() {
return _model.refer;
}
}