Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e04ed4

Browse files
feat: 添加issue评论区
1 parent 1ffe0b3 commit 7e04ed4

File tree

4 files changed

+377
-3
lines changed

4 files changed

+377
-3
lines changed

‎lib/page/comment/index.dart

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/material.dart';
22
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;
35

46
class Index extends StatefulWidget {
57
@override
@@ -17,9 +19,102 @@ class _IndexState extends State<Index> {
1719
AppLocalizations.$t('title_comment')
1820
),
1921
),
20-
body: Center(
21-
child: Text('评论'),
22-
),
22+
body: Container(
23+
padding: EdgeInsets.fromLTRB(16.0, 0 ,16.0, 0),
24+
child: _CommentList(context),
25+
)
26+
);
27+
}
28+
29+
Widget _CommentList(BuildContext context){
30+
return Store.connect<UserModel>(
31+
builder: (context, child, model) {
32+
if (model.flutter_ui_issues!=null&&model.flutter_ui_issues.issuesContent!=null&&model.flutter_ui_issues.issuesContent.length!=0) {
33+
return ListView.builder(
34+
itemCount: model.flutter_ui_issues.issuesContent.length,
35+
itemBuilder: (context, index) {
36+
return _CommentCard(context, model.flutter_ui_issues.issuesContent[index]);
37+
},
38+
);
39+
} else {
40+
return Center(
41+
child: Text('loading....'),
42+
);
43+
}
44+
}
45+
);
46+
}
47+
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)
65+
),
66+
child: Image.network(
67+
issuesContent.user.avatarUrl??'http://thumb10.jfcdns.com/2018-06/bce5b10ae530f530.png',
68+
fit: BoxFit.cover,
69+
),
70+
),
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,
77+
),
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+
],
92+
)
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
100+
),
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
113+
),
114+
),
115+
)
116+
],
117+
)
23118
);
24119
}
25120
}

‎lib/page/home.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class _IndexState extends State<Index> {
5454
// type: BottomNavigationBarType.fixed,
5555
currentIndex: _currentIndex,
5656
onTap: (int index) {
57+
if(index == 1&&_currentIndex!=index) {
58+
Store.value<UserModel>(context).getIssueFlutterUI();
59+
}
5760
_pageController.jumpToPage(index);
5861
},
5962
),

‎lib/store/models/user_model.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import 'package:efox_flutter/http/index.dart' as Http;
88
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;
11+
import '../objects/flutter_ui_issues.dart' show FlutterUiIssues;
1112

1213
class UserModelInfo {
1314
bool isStar = false; // 用户是否star了flutter ui项目
1415
FlutterUiInfo flutter_ui_info = FlutterUiInfo(); // flutter ui项目信息
16+
FlutterUiIssues flutter_ui_issues = FlutterUiIssues(); // flutter ui的issues内容
1517
}
1618

1719
class UserModel extends UserModelInfo with ChangeNotifier {
@@ -203,4 +205,24 @@ class UserModel extends UserModelInfo with ChangeNotifier {
203205
print('用户star flutter ui项目错误: $error');
204206
});
205207
}
208+
209+
/**
210+
* 获取flutter ui的issue内容
211+
*/
212+
getIssueFlutterUI() {
213+
var response = Http.get(
214+
url: 'https://api.github.com/repos/efoxTeam/flutter-ui/issues'
215+
);
216+
response.then((resp) {
217+
var data = {
218+
"issues_content": resp.data
219+
};
220+
print('获取flutter ui的issue内容:${data}');
221+
flutter_ui_issues = FlutterUiIssues.fromJson(data);
222+
notifyListeners();
223+
return flutter_ui_issues;
224+
}).catchError((error) {
225+
print('获取flutter ui的issue内容出错:$error');
226+
});
227+
}
206228
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /