Skip to content

Commit d49bce4

Browse files
committed
feat: issue评论详情
1 parent 7e04ed4 commit d49bce4

File tree

7 files changed

+447
-65
lines changed

7 files changed

+447
-65
lines changed

lib/page/comment/details.dart

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
3+
import 'package:efox_flutter/store/index.dart' show Store, UserModel;
4+
import 'package:efox_flutter/store/objects/flutter_ui_issues.dart' show IssuesContent;
5+
import 'package:efox_flutter/store/objects/issues_comment.dart' show IssuesDetails;
6+
7+
class Index extends StatefulWidget {
8+
int indexes;
9+
Index({ Key key, @required this.indexes }):super(key: key);
10+
@override
11+
_IndexState createState() => _IndexState();
12+
}
13+
14+
class _IndexState extends State<Index> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return Scaffold(
18+
appBar: AppBar(
19+
elevation: 0,
20+
centerTitle: true,
21+
title: Text(
22+
AppLocalizations.$t('title_comment_detials')
23+
),
24+
),
25+
body: Container(
26+
child: _ContentList(context)
27+
),
28+
);
29+
}
30+
31+
Widget _ContentList (BuildContext context) {
32+
return ListView(
33+
children: <Widget>[
34+
_IssueContent(context),
35+
_CommentContent(context)
36+
],
37+
);
38+
}
39+
40+
Widget _IssueContent (BuildContext context) {
41+
return Store.connect<UserModel>(
42+
builder: (context, child, model) {
43+
IssuesContent issuesContent = model.flutter_ui_issues.issuesContent[widget.indexes];
44+
return Column(
45+
crossAxisAlignment: CrossAxisAlignment.start,
46+
children: <Widget>[
47+
ListTile(
48+
leading: CircleAvatar(
49+
backgroundImage: NetworkImage(
50+
issuesContent.user.avatarUrl??'http://thumb10.jfcdns.com/2018-06/bce5b10ae530f530.png',
51+
),
52+
),
53+
title: Text('${issuesContent.user.login}'),
54+
subtitle: Text('更新时间:${issuesContent.updatedAt}'),
55+
),
56+
Container(
57+
padding: EdgeInsets.fromLTRB(20.0, 20, 20, 0),
58+
child: Text(
59+
'${issuesContent.title != '' ? issuesContent.title : '无标题'} #${issuesContent.number}',
60+
style: Theme.of(context).textTheme.title,
61+
),
62+
),
63+
Container(
64+
padding: EdgeInsets.fromLTRB(20.0, 10, 20, 20.0),
65+
child: Text(
66+
issuesContent.body,
67+
// != '' ?issuesContent.body:'无主体内容'
68+
style: Theme.of(context).textTheme.subhead
69+
),
70+
),
71+
Divider(
72+
height: 1,
73+
)
74+
],
75+
);
76+
}
77+
);
78+
}
79+
80+
Widget _CommentContent (BuildContext context) {
81+
return FutureBuilder(
82+
future: _getIssueComment(context),
83+
builder: (BuildContext context, AsyncSnapshot snapshot) {
84+
if (snapshot.connectionState == ConnectionState.waiting) {
85+
return Container(
86+
padding: EdgeInsets.all(20),
87+
child: Center(
88+
child: Text('loading....'),
89+
),
90+
);
91+
} else if(snapshot.connectionState == ConnectionState.done) {
92+
if (snapshot.hasData) {
93+
return Store.connect<UserModel>(
94+
builder: (context, child, model) {
95+
List<Widget> items = [];
96+
for(var issuesDetails in model.issues_comment.issuesDetails) {
97+
items.add(_CommentContentItem(context, issuesDetails));
98+
}
99+
return Column(
100+
children: items,
101+
);
102+
}
103+
);
104+
} else {
105+
return Center(
106+
child: Text('暂无数据'),
107+
);
108+
}
109+
}
110+
},
111+
);
112+
}
113+
114+
Future<String> _getIssueComment(BuildContext context) async {
115+
IssuesContent issuesContent = Store.value<UserModel>(context).flutter_ui_issues.issuesContent[widget.indexes];
116+
await Store.value<UserModel>(context).getIssueComment(issuesContent.number);
117+
return 'end';
118+
}
119+
120+
Widget _CommentContentItem(BuildContext context, IssuesDetails issuesDetails) {
121+
return Container(
122+
padding: EdgeInsets.fromLTRB(10, 20, 10, 0),
123+
child: Column(
124+
children: <Widget>[
125+
ListTile(
126+
leading: CircleAvatar(
127+
backgroundImage: NetworkImage(
128+
issuesDetails.user.avatarUrl??'http://thumb10.jfcdns.com/2018-06/bce5b10ae530f530.png',
129+
),
130+
),
131+
title: Text('${issuesDetails.user.login}'),
132+
subtitle: Text('${issuesDetails.body}')
133+
),
134+
Divider(height: 1,)
135+
],
136+
),
137+
);
138+
}
139+
}

lib/page/comment/index.dart

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
33
import 'package:efox_flutter/store/index.dart' show Store, UserModel;
44
import 'package:efox_flutter/store/objects/flutter_ui_issues.dart' show IssuesContent;
5+
import 'package:efox_flutter/router/index.dart' show FluroRouter;
56

67
class Index extends StatefulWidget {
78
@override
@@ -33,7 +34,7 @@ class _IndexState extends State<Index> {
3334
return ListView.builder(
3435
itemCount: model.flutter_ui_issues.issuesContent.length,
3536
itemBuilder: (context, index) {
36-
return _CommentCard(context, model.flutter_ui_issues.issuesContent[index]);
37+
return _CommentCard(context, model.flutter_ui_issues.issuesContent[index], index);
3738
},
3839
);
3940
} else {
@@ -45,76 +46,82 @@ class _IndexState extends State<Index> {
4546
);
4647
}
4748

48-
Widget _CommentCard(BuildContext context, IssuesContent issuesContent) {
49-
return Card(
50-
elevation: 4.0,
51-
child: Stack(
52-
alignment: Alignment.topCenter,
53-
children: <Widget>[
54-
Column(
55-
crossAxisAlignment: CrossAxisAlignment.start,
56-
children: <Widget>[
57-
AspectRatio(
58-
aspectRatio: 16/9,
59-
child: ClipRRect(
60-
borderRadius: BorderRadius.only(
61-
topLeft: Radius.circular(6.0),
62-
topRight: Radius.circular(6.0),
63-
bottomLeft: Radius.circular(6.0),
64-
bottomRight: Radius.circular(6.0)
49+
Widget _CommentCard(BuildContext context, IssuesContent issuesContent, int index) {
50+
return GestureDetector(
51+
onTap: () {
52+
// Store.value<UserModel>(context).getIssueComment(issuesContent.number);
53+
FluroRouter.router.navigateTo(context, '/commentdetails?indexes=${index}',);
54+
},
55+
child: Card(
56+
elevation: 4.0,
57+
child: Stack(
58+
alignment: Alignment.topCenter,
59+
children: <Widget>[
60+
Column(
61+
crossAxisAlignment: CrossAxisAlignment.start,
62+
children: <Widget>[
63+
AspectRatio(
64+
aspectRatio: 16/9,
65+
child: ClipRRect(
66+
borderRadius: BorderRadius.only(
67+
topLeft: Radius.circular(6.0),
68+
topRight: Radius.circular(6.0),
69+
bottomLeft: Radius.circular(6.0),
70+
bottomRight: Radius.circular(6.0)
71+
),
72+
child: Image.network(
73+
issuesContent.user.avatarUrl??'http://thumb10.jfcdns.com/2018-06/bce5b10ae530f530.png',
74+
fit: BoxFit.cover,
75+
),
6576
),
66-
child: Image.network(
67-
issuesContent.user.avatarUrl??'http://thumb10.jfcdns.com/2018-06/bce5b10ae530f530.png',
68-
fit: BoxFit.cover,
77+
),
78+
Container(
79+
padding: EdgeInsets.fromLTRB(20.0, 20, 20, 0),
80+
child: Text(
81+
'${issuesContent.title != '' ? issuesContent.title : '无标题'} #${issuesContent.number}',
82+
style: Theme.of(context).textTheme.title,
6983
),
7084
),
71-
),
72-
Container(
73-
padding: EdgeInsets.fromLTRB(20.0, 20, 20, 0),
74-
child: Text(
75-
'${issuesContent.title != '' ? issuesContent.title : '无标题'} #${issuesContent.number}',
76-
style: Theme.of(context).textTheme.title,
85+
Container(
86+
padding: EdgeInsets.fromLTRB(20.0, 10, 20, 0),
87+
child: Column(
88+
children: <Widget>[
89+
Text(
90+
'创建时间:${issuesContent.createdAt}',
91+
style: TextStyle(color: Colors.black54, fontSize: 12)
92+
),
93+
Text(
94+
'更新时间:${issuesContent.updatedAt}',
95+
style: TextStyle(color: Colors.black54, fontSize: 12)
96+
)
97+
],
98+
)
7799
),
78-
),
79-
Container(
80-
padding: EdgeInsets.fromLTRB(20.0, 10, 20, 0),
81-
child: Column(
82-
children: <Widget>[
83-
Text(
84-
'创建时间:${issuesContent.createdAt}',
85-
style: TextStyle(color: Colors.black54, fontSize: 12)
86-
),
87-
Text(
88-
'更新时间:${issuesContent.updatedAt}',
89-
style: TextStyle(color: Colors.black54, fontSize: 12)
90-
)
91-
],
100+
Container(
101+
padding: EdgeInsets.fromLTRB(20.0, 10, 20, 20.0),
102+
child: Text(
103+
issuesContent.body,
104+
// != '' ?issuesContent.body:'无主体内容'
105+
style: Theme.of(context).textTheme.subhead
106+
),
92107
)
93-
),
94-
Container(
95-
padding: EdgeInsets.fromLTRB(20.0, 10, 20, 20.0),
96-
child: Text(
97-
issuesContent.body,
98-
// != '' ?issuesContent.body:'无主体内容'
99-
style: Theme.of(context).textTheme.subhead
108+
],
109+
),
110+
Positioned(
111+
top: 10,
112+
left: 10,
113+
child: Text(
114+
issuesContent.user.login,
115+
style: TextStyle(
116+
color: Theme.of(context).primaryColor,
117+
fontWeight: FontWeight.bold,
118+
fontSize: 20
100119
),
101-
)
102-
],
103-
),
104-
Positioned(
105-
top: 10,
106-
left: 10,
107-
child: Text(
108-
issuesContent.user.login,
109-
style: TextStyle(
110-
color: Theme.of(context).primaryColor,
111-
fontWeight: FontWeight.bold,
112-
fontSize: 20
113120
),
114-
),
115-
)
116-
],
117-
)
121+
)
122+
],
123+
)
124+
),
118125
);
119126
}
120127
}

lib/router/index.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import 'package:flutter/widgets.dart';
22
import 'package:fluro/fluro.dart';
33
//首页
44
import 'package:efox_flutter/page/home.dart' as HomePage;
5+
// 评论详细页面
6+
import 'package:efox_flutter/page/comment/details.dart' as CommentDetails;
57
import 'package:efox_flutter/widget/index.dart' as WidgetConfig;
68
import 'handles.dart';
79
//统计
@@ -24,6 +26,18 @@ class FluroRouter {
2426
},
2527
),
2628
);
29+
// 评论详情页面
30+
router.define(
31+
'/commentdetails',
32+
handler: Handler(
33+
handlerFunc: (BuildContext context, Map<String, dynamic> params) {
34+
String indexes = params["indexes"]?.first;
35+
return CommentDetails.Index(
36+
indexes: int.parse('${indexes}')
37+
);
38+
}
39+
)
40+
);
2741

2842
router.define('/webview', handler: webviewHandler);
2943

lib/store/models/user_model.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import 'package:efox_flutter/utils/localStorage.dart' show LocalStorage;
99
import 'package:efox_flutter/config/index.dart' show owner_repo;
1010
import '../objects/flutter_ui_info.dart' show FlutterUiInfo;
1111
import '../objects/flutter_ui_issues.dart' show FlutterUiIssues;
12+
import '../objects/issues_comment.dart' show IssuesComment;
1213

1314
class UserModelInfo {
1415
bool isStar = false; // 用户是否star了flutter ui项目
1516
FlutterUiInfo flutter_ui_info = FlutterUiInfo(); // flutter ui项目信息
1617
FlutterUiIssues flutter_ui_issues = FlutterUiIssues(); // flutter ui的issues内容
18+
IssuesComment issues_comment = IssuesComment(); // issues comment内容
1719
}
1820

1921
class UserModel extends UserModelInfo with ChangeNotifier {
@@ -211,7 +213,7 @@ class UserModel extends UserModelInfo with ChangeNotifier {
211213
*/
212214
getIssueFlutterUI() {
213215
var response = Http.get(
214-
url: 'https://api.github.com/repos/efoxTeam/flutter-ui/issues'
216+
url: 'https://api.github.com/repos/$owner_repo/issues'
215217
);
216218
response.then((resp) {
217219
var data = {
@@ -225,4 +227,23 @@ class UserModel extends UserModelInfo with ChangeNotifier {
225227
print('获取flutter ui的issue内容出错:$error');
226228
});
227229
}
230+
231+
/**
232+
* 获取对应issue下的回复内容
233+
*/
234+
getIssueComment(int number) async {
235+
var response = await Http.get(
236+
url: 'https://api.github.com/repos/$owner_repo/issues/$number/comments'
237+
);
238+
try {
239+
var data = {
240+
"issues_details": response.data
241+
};
242+
print('获取对应issue下的回复内容:${response.data}');
243+
issues_comment = IssuesComment.fromJson(data);
244+
notifyListeners();
245+
} catch(error) {
246+
print('获取对应issue下的回复内容出错:$error');
247+
}
248+
}
228249
}

0 commit comments

Comments
 (0)