X Tutup
Skip to content

Commit ed9e2a0

Browse files
committed
focus
1 parent fdfc3b0 commit ed9e2a0

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

lib/common/dao/UserDao.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:convert';
2+
import 'dart:io';
23

34
import 'package:dio/dio.dart';
45
import 'package:gsy_github_app_flutter/common/config/Config.dart';
@@ -195,4 +196,23 @@ class UserDao {
195196
var res = await HttpManager.netFetch(url, null, null, new Options(method: "PATCH"));
196197
return res;
197198
}
199+
200+
/**
201+
* 检查用户关注状态
202+
*/
203+
static checkFollowDao(name) async {
204+
String url = Address.doFollow(name);
205+
var res = await HttpManager.netFetch(url, null, null, new Options(contentType: ContentType.TEXT), noTip: true);
206+
return new DataResult(res.data, res.result);
207+
}
208+
209+
/**
210+
* 关注用户
211+
*/
212+
static doFollowDao(name, bool followed) async {
213+
String url = Address.doFollow(name);
214+
print(followed);
215+
var res = await HttpManager.netFetch(url, null, null, new Options(method: !followed ? "PUT" : "DELETE"), noTip: true);
216+
return new DataResult(res.data, res.result);
217+
}
198218
}

lib/page/PersonPage.dart

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:gsy_github_app_flutter/common/dao/EventDao.dart';
55
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
66
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
77
import 'package:gsy_github_app_flutter/common/model/User.dart';
8+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
89
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
910
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
1011
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
@@ -27,11 +28,14 @@ class PersonPage extends StatefulWidget {
2728
}
2829

2930
class _PersonState extends GSYListState<PersonPage> {
30-
3131
final String userName;
3232

3333
String beStaredCount = "---";
3434

35+
bool focusStatus = false;
36+
37+
String focus = "";
38+
3539
User userInfo = User.empty();
3640

3741
_PersonState(this.userName);
@@ -61,7 +65,7 @@ class _PersonState extends GSYListState<PersonPage> {
6165
}
6266
resolveDataResult(res);
6367
isLoading = false;
64-
68+
_getFocusStatus();
6569
ReposDao.getUserRepository100StatusDao(_getUserName()).then((res) {
6670
if (res != null && res.result) {
6771
setState(() {
@@ -72,6 +76,13 @@ class _PersonState extends GSYListState<PersonPage> {
7276
return null;
7377
}
7478

79+
_getFocusStatus() async {
80+
var focusRes = await UserDao.checkFollowDao(userName);
81+
setState(() {
82+
focus = (focusRes != null && focusRes.result) ? "已关注" : "关注";
83+
focusStatus = (focusRes != null && focusRes.result);
84+
});
85+
}
7586

7687
_renderEventItem(index) {
7788
if (index == 0) {
@@ -90,10 +101,8 @@ class _PersonState extends GSYListState<PersonPage> {
90101
@override
91102
bool get wantKeepAlive => true;
92103

93-
94104
@override
95-
requestRefresh() async {
96-
}
105+
requestRefresh() async {}
97106

98107
@override
99108
requestLoadMore() async {
@@ -106,20 +115,30 @@ class _PersonState extends GSYListState<PersonPage> {
106115
@override
107116
bool get needHeader => true;
108117

109-
110118
@override
111119
Widget build(BuildContext context) {
112120
return new Scaffold(
113121
appBar: new AppBar(
114122
title: new Text((userInfo != null && userInfo.login != null) ? userInfo.login : ""),
115123
),
124+
floatingActionButton: new FloatingActionButton(
125+
child: new Text(focus),
126+
onPressed: () {
127+
if (focus == '') {
128+
return;
129+
}
130+
CommonUtils.showLoadingDialog(context);
131+
UserDao.doFollowDao(userName, focusStatus).then((res) {
132+
Navigator.pop(context);
133+
_getFocusStatus();
134+
});
135+
}),
116136
body: GSYPullLoadWidget(
117137
pullLoadWidgetControl,
118-
(BuildContext context, int index) => _renderEventItem(index),
138+
(BuildContext context, int index) => _renderEventItem(index),
119139
handleRefresh,
120140
onLoadMore,
121141
refreshKey: refreshIndicatorKey,
122142
));
123143
}
124-
125144
}

lib/widget/ReposHeaderItem.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ReposHeaderItem extends StatelessWidget {
6161
),
6262
child: new Container(
6363
decoration: new BoxDecoration(
64-
color: Color(0x90000000),
64+
color: Color(GSYColors.primaryDarkValue & 0xA0FFFFFF),
6565
),
6666
child: new Padding(
6767
padding: new EdgeInsets.only(left: 10.0, top: 10.0, right: 10.0, bottom: 10.0),

0 commit comments

Comments
 (0)
X Tutup