forked from Sky24n/flutter_wanandroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeline_page.dart
274 lines (232 loc) · 8.78 KB
/
timeline_page.dart
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
class TimelinePage extends StatefulWidget {
final String title;
TimelinePage(this.title);
@override
State<StatefulWidget> createState() {
return new _TimelinePageState();
}
}
class ZHAliPayTimelineInfo implements TimelineInfo {
String suffixAgo() => '前';
String suffixAfter() => '后';
String lessThanTenSecond() => '刚刚';
String customYesterday() => '昨天';
bool keepOneDay() => true;
bool keepTwoDays() => false;
String oneMinute(int minutes) => '$minutes分';
String minutes(int minutes) => '$minutes分';
String anHour(int hours) => '$hours小时';
String hours(int hours) => '$hours小时';
String oneDay(int days) => '$days天';
String days(int days) => '$days天';
DayFormat dayFormat() => DayFormat.Full;
}
class ENAliPayTimelineInfo implements TimelineInfo {
String suffixAgo() => ' ago';
String suffixAfter() => ' after';
String lessThanTenSecond() => 'just now';
String customYesterday() => 'Yesterday';
bool keepOneDay() => true;
bool keepTwoDays() => false;
String oneMinute(int minutes) => 'a minute';
String minutes(int minutes) => '$minutes minutes';
String anHour(int hours) => 'an hour';
String hours(int hours) => '$hours hours';
String oneDay(int days) => 'a day';
String days(int days) => '$days days';
DayFormat dayFormat() => DayFormat.Full;
}
class _TimelinePageState extends State<TimelinePage> {
bool isChinese = true;
static const int weChat = 1;
static const int weiBo = 2;
static const int aliPay = 3;
int dateType = aliPay;
DayFormat _dayFormat = DayFormat.Full;
List<int> dateTimeList = new List();
int _locTime = DateTime.now().millisecondsSinceEpoch;
void _update() {
setState(() {});
}
@override
void initState() {
super.initState();
setLocaleInfo('zh_alipay', ZHAliPayTimelineInfo());
setLocaleInfo('en_alipay', ENAliPayTimelineInfo());
// _locTime = new DateTime(2018, 10, 3, 16, 30, 30).millisecondsSinceEpoch;
dateTimeList.add(_locTime - 2000);
dateTimeList.add(_locTime - 1000 * 60 * 2);
dateTimeList.add(_locTime - 1000 * 60 * 60 * 2);
dateTimeList.add(_locTime - 1000 * 60 * 60 * 12);
dateTimeList.add(_locTime - 1000 * 60 * 60 * 25);
dateTimeList.add(_locTime - 1000 * 60 * 60 * 48);
dateTimeList.add(_locTime - 1000 * 60 * 60 * 72);
dateTimeList.add(DateTime(2018, 9, 18, 16, 16, 16).millisecondsSinceEpoch);
dateTimeList.add(DateTime(2017, 9, 18, 16, 16, 16).millisecondsSinceEpoch);
}
String _getLocale() {
String locale;
switch (dateType) {
case aliPay:
// locale = isChinese ? 'zh_alipay' : 'en_alipay';
locale = isChinese ? 'zh_normal' : 'en_normal';
_dayFormat = DayFormat.Full;
break;
case weChat:
locale = isChinese ? 'zh' : 'en';
_dayFormat = DayFormat.Simple;
break;
case weiBo:
locale = isChinese ? 'zh' : 'en';
_dayFormat = DayFormat.Common;
break;
}
return locale;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
centerTitle: true,
),
body: new Column(
children: <Widget>[
new Card(
elevation: 4.0,
margin: const EdgeInsets.all(10.0),
child: new Column(
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(
top: 16.0, left: 5.0, right: 5.0),
child: new Column(
children: <Widget>[
new Text("中文",
style: new TextStyle(
fontSize: 12.0, color: Colors.grey[700])),
new Checkbox(
value: (isChinese == true),
activeColor: Colors.red,
onChanged: (value) {
isChinese = true;
_update();
})
],
),
),
new Padding(
padding: const EdgeInsets.only(
top: 16.0, left: 5.0, right: 5.0),
child: new Column(
children: <Widget>[
new Text("English",
style: new TextStyle(
fontSize: 12.0, color: Colors.grey[700])),
new Checkbox(
value: (isChinese == false),
activeColor: Colors.red,
onChanged: (value) {
isChinese = false;
_update();
})
],
),
),
],
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(
top: 16.0, left: 5.0, right: 5.0),
child: new Column(
children: <Widget>[
new Text("支付宝",
style: new TextStyle(
fontSize: 12.0, color: Colors.grey[700])),
new Checkbox(
value: (dateType == aliPay),
onChanged: (value) {
dateType = aliPay;
_update();
})
],
),
),
new Padding(
padding: const EdgeInsets.only(
top: 16.0, left: 5.0, right: 5.0),
child: new Column(
children: <Widget>[
new Text("微信",
style: new TextStyle(
fontSize: 12.0, color: Colors.grey[700])),
new Checkbox(
value: (dateType == weChat),
onChanged: (value) {
dateType = weChat;
_update();
})
],
),
),
new Padding(
padding: const EdgeInsets.only(
top: 16.0, left: 5.0, right: 5.0),
child: new Column(
children: <Widget>[
new Text("微博",
style: new TextStyle(
fontSize: 12.0, color: Colors.grey[700])),
new Checkbox(
value: (dateType == weiBo),
onChanged: (value) {
dateType = weiBo;
_update();
})
],
),
),
],
),
],
),
),
new Expanded(
child: new Card(
elevation: 4.0,
margin: const EdgeInsets.all(10.0),
child: new ListView.builder(
itemCount: dateTimeList.length,
itemBuilder: (BuildContext context, int index) {
int timeMillis = dateTimeList[index];
String timeline = TimelineUtil.format(timeMillis,
locTimeMillis: _locTime,
locale: _getLocale(),
dayFormat: _dayFormat);
return Container(
alignment: Alignment.center,
height: 50.0,
child: new Text('$timeline'),
decoration: new BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(2.0)),
color: Colors.white,
border: new Border.all(
width: 0.33, color: Color(0XFFEFEFEF))));
}),
),
flex: 1,
)
],
),
);
}
}