Skip to content

Commit 74216fa

Browse files
committed
1、优化排行榜UI;2、打卡防作弊:从网络获取当天时间
1 parent 087761c commit 74216fa

File tree

9 files changed

+222
-92
lines changed

9 files changed

+222
-92
lines changed

images/3.0x/no1.png

5.56 KB
Loading

images/3.0x/no2.png

4.36 KB
Loading

images/3.0x/no3.png

4.61 KB
Loading

lib/page/home/drawer/rank_page.dart

+78-34
Original file line numberDiff line numberDiff line change
@@ -57,42 +57,86 @@ class _RankPageState extends State<RankPage> {
5757
}
5858

5959
Widget _item(BmobUserEntity entity, int index) {
60-
return Padding(
61-
padding: EdgeInsets.symmetric(horizontal: pt(16), vertical: pt(10)),
62-
child: Row(
63-
children: <Widget>[
64-
Padding(
65-
padding: EdgeInsets.only(right: pt(8)),
66-
child: Container(
67-
decoration: ShapeDecoration(
68-
shape: CircleBorder(side: BorderSide(color: Colors.red))),
69-
padding: EdgeInsets.all(pt(2.5)),
70-
child: Text(
71-
'${index + 1}',
72-
style: TextStyle(
73-
color: Colors.red,
74-
fontSize: 12
75-
),
76-
),
60+
Color color;
61+
Widget rank;
62+
TextStyle style;
63+
if (index == 0) {
64+
color = Colors.red;
65+
rank = Image.asset(
66+
'images/no1.png',
67+
width: pt(22),
68+
height: pt(22),
69+
color: color,
70+
);
71+
style = TextStyle(fontWeight: FontWeight.w700, color: color);
72+
} else if (index == 1) {
73+
color = Colors.orange;
74+
rank = Image.asset(
75+
'images/no2.png',
76+
width: pt(22),
77+
height: pt(22),
78+
color: color,
79+
);
80+
style = TextStyle(fontWeight: FontWeight.w600, color: color);
81+
} else if (index == 2) {
82+
color = Colors.purple;
83+
rank = Image.asset(
84+
'images/no3.png',
85+
width: pt(22),
86+
height: pt(22),
87+
color: color,
88+
);
89+
style = TextStyle(fontWeight: FontWeight.w500, color: color);
90+
} else {
91+
color = Colors.black;
92+
rank = Container(
93+
decoration: ShapeDecoration(
94+
shape: CircleBorder(side: BorderSide(color: Colors.red))),
95+
padding: EdgeInsets.all(pt(2.5)),
96+
child: Text(
97+
'${index + 1}',
98+
style: TextStyle(color: Colors.red, fontSize: 12),
99+
),
100+
);
101+
style = TextStyle(fontWeight: FontWeight.normal, color: color);
102+
}
103+
104+
return DecoratedBox(
105+
decoration: BoxDecoration(
106+
color: Colors.white,
107+
),
108+
child: Padding(
109+
padding: EdgeInsets.symmetric(horizontal: pt(16), vertical: pt(10)),
110+
child: Row(
111+
children: <Widget>[
112+
Padding(
113+
padding: EdgeInsets.only(right: pt(8)),
114+
child: rank,
77115
),
78-
),
79-
Expanded(
80-
child: Column(
81-
crossAxisAlignment: CrossAxisAlignment.start,
82-
children: <Widget>[
83-
Text(
84-
entity.userName ?? 'unknow',
85-
style: TextStyle(fontSize: 18),
86-
),
87-
Text(
88-
entity.signature ?? '',
89-
style: TextStyle(fontSize: 12),
90-
),
91-
],
116+
Expanded(
117+
child: Column(
118+
crossAxisAlignment: CrossAxisAlignment.start,
119+
children: <Widget>[
120+
Text(
121+
entity.userName ?? 'unknow',
122+
style: TextStyle(
123+
fontSize: 18,
124+
fontWeight: style.fontWeight,
125+
color: style.color),
126+
),
127+
Text(
128+
entity.signature ?? '',
129+
style: TextStyle(
130+
fontSize: 12,
131+
fontWeight: style.fontWeight,
132+
color: style.color),
133+
),
134+
],
135+
),
92136
),
93-
),
94-
getLevelWidgets(entity.level),
95-
],
137+
getLevelWidgets(entity.level),
138+
],
139+
),
96140
),
97141
);
98142
}

lib/page/home/home/home_drawer.dart

+51-28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_bloc/flutter_bloc.dart';
33
import 'package:wanandroid_flutter/entity/bmob_feedback_entity.dart';
44
import 'package:wanandroid_flutter/entity/bmob_user_entity.dart';
5+
import 'package:wanandroid_flutter/http/index.dart';
56
import 'package:wanandroid_flutter/main.dart';
67
import 'package:wanandroid_flutter/page/account/login_wanandroid_page.dart';
78
import 'package:wanandroid_flutter/page/home/drawer/about_page.dart';
@@ -27,17 +28,21 @@ class HomeDrawer extends StatefulWidget {
2728

2829
class _HomeDrawerState extends State<HomeDrawer> {
2930
HomeBloc homeBloc;
31+
bool hasSignin = false;
3032

3133
@override
3234
void initState() {
3335
super.initState();
3436
homeBloc = BlocProvider.of<HomeBloc>(context);
37+
if (widget.bmobUserEntity != null) {
38+
checkTodayHasSignin(DateTime.parse(widget.bmobUserEntity.updatedAt));
39+
} else {
40+
hasSignin = false;
41+
}
3542
}
3643

3744
@override
3845
Widget build(BuildContext context) {
39-
bool canSignin = widget.bmobUserEntity != null &&
40-
!isToday(DateTime.parse(widget.bmobUserEntity.updatedAt));
4146
return BlocListener<HomeEvent, HomeState>(
4247
bloc: homeBloc,
4348
listener: (context, state) {
@@ -67,16 +72,18 @@ class _HomeDrawerState extends State<HomeDrawer> {
6772
: GestureDetector(
6873
behavior: HitTestBehavior.opaque,
6974
onTap: () {
70-
if (canSignin) {
71-
widget.bmobUserEntity.level++;
72-
homeBloc.dispatch(
73-
UpdateBmobInfo(widget.bmobUserEntity));
75+
if (!hasSignin) {
76+
BmobUserEntity copy = widget.bmobUserEntity
77+
.copyWith(
78+
level: widget.bmobUserEntity.level +
79+
1);
80+
homeBloc.dispatch(UpdateBmobInfo(copy));
7481
}
7582
},
7683
child: Row(
7784
children: <Widget>[
7885
Text(
79-
canSignin ? res.signin : res.signined,
86+
!hasSignin ? res.signin : res.signined,
8087
style: TextStyle(color: Colors.white),
8188
),
8289
SizedBox(
@@ -224,21 +231,21 @@ class _HomeDrawerState extends State<HomeDrawer> {
224231
});
225232
}
226233
}),
227-
// FlatButton(
228-
// child: Text('去测试页'),
229-
// onPressed: () {
230-
// Navigator.push(
231-
// context,
232-
// MaterialPageRoute(
233-
// builder: (context) {
234-
// return Scaffold(
235-
// body: TestPage(),
236-
// );
237-
// },
238-
// ),
239-
// );
240-
// },
241-
// ),
234+
FlatButton(
235+
child: Text('去测试页'),
236+
onPressed: () {
237+
Navigator.push(
238+
context,
239+
MaterialPageRoute(
240+
builder: (context) {
241+
return Scaffold(
242+
body: TestPage(),
243+
);
244+
},
245+
),
246+
);
247+
},
248+
),
242249
// FlatButton(
243250
// child: Text('去nest'),
244251
// onPressed: () {
@@ -269,15 +276,30 @@ class _HomeDrawerState extends State<HomeDrawer> {
269276
);
270277
}
271278

272-
//更新时间是否在今天?
273-
bool isToday(DateTime updateTime) {
274-
DateTime now = DateTime.now();
279+
280+
Future checkTodayHasSignin(DateTime updateTime) async {
281+
///为防止打卡作弊,当前时间从网络上获取
282+
DateTime now;
283+
try {
284+
Response response = await dio.get(
285+
'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp');
286+
Map<String, dynamic> data =
287+
(response.data as Map<String, dynamic>)['data'];
288+
String todayMills = data['t'];
289+
now = DateTime.fromMillisecondsSinceEpoch(int.parse(todayMills),
290+
isUtc: true);
291+
} catch (e) {
292+
print(e);
293+
now = DateTime.now();
294+
}
295+
275296
DateTime today = DateTime(
276297
now.year,
277298
now.month,
278299
now.day,
279300
);
280-
return updateTime.isAfter(today.toUtc());
301+
hasSignin = updateTime.isAfter(today.toUtc());
302+
setState(() {});
281303
}
282304

283305
showSignatureDialog() {
@@ -359,8 +381,9 @@ class _HomeDrawerState extends State<HomeDrawer> {
359381
FlatButton(
360382
child: Text(res.confirm),
361383
onPressed: () {
362-
BmobFeedbackEntity feedback = BmobFeedbackEntity(widget.userName ?? '未登录用户', controller.text ?? '空');
363-
feedback.save().then((_){
384+
BmobFeedbackEntity feedback = BmobFeedbackEntity(
385+
widget.userName ?? '未登录用户', controller.text ?? '空');
386+
feedback.save().then((_) {
364387
print('feedback send success');
365388
});
366389
Navigator.of(context).pop();

lib/page/home/project/project_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class _ProjectItemState extends State<ProjectItem>
630630
),
631631
),
632632
GestureDetector(
633-
behavior: HitTestBehavior.opaque,
633+
// behavior: HitTestBehavior.opaque,
634634
onTap: () {
635635
DisplayUtil.showMsg(context,
636636
text: 'click type ${widget.data.chapterName}(待实现)');

0 commit comments

Comments
 (0)