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
+ import 'package:efox_flutter/page/app_login/index.dart' as LoginIndex;
7
+
8
+ class Index extends StatefulWidget {
9
+ int indexes;
10
+ Index ({ Key key, @required this .indexes }): super (key: key);
11
+ @override
12
+ _IndexState createState () => _IndexState ();
13
+ }
14
+
15
+ class _IndexState extends State <Index > {
16
+ final TextEditingController _controller = TextEditingController ();
17
+ var _getComment;
18
+ bool isCanSend = false ;
19
+
20
+ @override
21
+ void initState () {
22
+ // TODO: implement initState
23
+ super .initState ();
24
+ _getComment = this ._getIssueComment (context);
25
+ }
26
+
27
+ @override
28
+ Widget build (BuildContext context) {
29
+ return Scaffold (
30
+ appBar: AppBar (
31
+ elevation: 0 ,
32
+ centerTitle: true ,
33
+ title: Text (
34
+ AppLocalizations .$t ('title_comment_detials' )
35
+ ),
36
+ ),
37
+ body: Stack (
38
+ children: < Widget > [
39
+ Container (
40
+ margin: EdgeInsets .only (bottom: 50 ),
41
+ child: _ContentList (context),
42
+ ),
43
+ _SendComment (context)
44
+ ],
45
+ )
46
+ );
47
+ }
48
+
49
+ Widget _ContentList (BuildContext context) {
50
+ return ListView (
51
+ children: < Widget > [
52
+ _IssueContent (context),
53
+ _CommentContent (context)
54
+ ],
55
+ );
56
+ }
57
+
58
+ Widget _IssueContent (BuildContext context) {
59
+ return Store .connect <UserModel >(
60
+ builder: (context, child, model) {
61
+ IssuesContent issuesContent = model.flutter_ui_issues.issuesContent[widget.indexes];
62
+ return Column (
63
+ crossAxisAlignment: CrossAxisAlignment .start,
64
+ children: < Widget > [
65
+ ListTile (
66
+ leading: CircleAvatar (
67
+ backgroundImage: NetworkImage (
68
+ issuesContent.user.avatarUrl?? 'http://thumb10.jfcdns.com/2018-06/bce5b10ae530f530.png' ,
69
+ ),
70
+ ),
71
+ title: Text ('${issuesContent .user .login }' ),
72
+ subtitle: Text ('更新时间:${issuesContent .updatedAt }' ),
73
+ ),
74
+ Container (
75
+ padding: EdgeInsets .fromLTRB (20.0 , 20 , 20 , 0 ),
76
+ child: Text (
77
+ '${issuesContent .title != '' ? issuesContent .title : '无标题' } #${issuesContent .number }' ,
78
+ style: Theme .of (context).textTheme.title,
79
+ ),
80
+ ),
81
+ Container (
82
+ padding: EdgeInsets .fromLTRB (20.0 , 10 , 20 , 20.0 ),
83
+ child: Text (
84
+ issuesContent.body,
85
+ // != '' ?issuesContent.body:'无主体内容'
86
+ style: Theme .of (context).textTheme.subhead
87
+ ),
88
+ ),
89
+ Divider (
90
+ height: 1 ,
91
+ )
92
+ ],
93
+ );
94
+ }
95
+ );
96
+ }
97
+
98
+ Widget _CommentContent (BuildContext context) {
99
+ return FutureBuilder (
100
+ future: _getComment,
101
+ builder: (BuildContext context, AsyncSnapshot snapshot) {
102
+ if (snapshot.connectionState == ConnectionState .waiting) {
103
+ return Container (
104
+ padding: EdgeInsets .all (20 ),
105
+ child: Center (
106
+ child: Text ('loading....' ),
107
+ ),
108
+ );
109
+ } else if (snapshot.connectionState == ConnectionState .done) {
110
+ if (snapshot.hasData) {
111
+ return Store .connect <UserModel >(
112
+ builder: (context, child, model) {
113
+ List <Widget > items = [];
114
+ for (var issuesDetails in model.issues_comment.issuesDetails) {
115
+ items.add (_CommentContentItem (context, issuesDetails));
116
+ }
117
+ return Column (
118
+ children: items,
119
+ );
120
+ }
121
+ );
122
+ } else {
123
+ return Center (
124
+ child: Text ('暂无数据' ),
125
+ );
126
+ }
127
+ }
128
+ },
129
+ );
130
+ }
131
+
132
+ Future <String > _getIssueComment (BuildContext context) async {
133
+ IssuesContent issuesContent = Store .valueNotCtx <UserModel >().flutter_ui_issues.issuesContent[widget.indexes];
134
+ await Store .valueNotCtx <UserModel >().getIssueComment (issuesContent.number);
135
+ return 'end' ;
136
+ }
137
+
138
+ Widget _CommentContentItem (BuildContext context, IssuesDetails issuesDetails) {
139
+ return Container (
140
+ padding: EdgeInsets .fromLTRB (10 , 20 , 10 , 0 ),
141
+ child: Column (
142
+ children: < Widget > [
143
+ ListTile (
144
+ leading: CircleAvatar (
145
+ backgroundImage: NetworkImage (
146
+ issuesDetails.user.avatarUrl?? 'http://thumb10.jfcdns.com/2018-06/bce5b10ae530f530.png' ,
147
+ ),
148
+ ),
149
+ title: Text ('${issuesDetails .user .login }' ),
150
+ subtitle: Text ('${issuesDetails .body }' )
151
+ ),
152
+ Divider (height: 1 ,)
153
+ ],
154
+ ),
155
+ );
156
+ }
157
+
158
+ Widget _SendComment (BuildContext context) {
159
+ return Positioned (
160
+ bottom: 0 ,
161
+ left: 0 ,
162
+ child: Container (
163
+ width: MediaQuery .of (context).size.width,
164
+ height: 50 ,
165
+ decoration: BoxDecoration (
166
+ color: Colors .white,
167
+ border: Border (
168
+ top: BorderSide (width: 0.5 , color: Color (int .parse ('0xffe4e4e4' )))
169
+ )
170
+ ),
171
+ child: Row (
172
+ children: < Widget > [
173
+ Expanded (
174
+ flex: 1 ,
175
+ child: _InputBox (),
176
+ ),
177
+ Store .connect <UserModel >(
178
+ builder: (context, child, model) {
179
+ IssuesContent issuesContent = model.flutter_ui_issues.issuesContent[widget.indexes];
180
+ return GestureDetector (
181
+ onTap: () async {
182
+ if (isCanSend) {
183
+ if (model.user.id != null ) {
184
+ print ('发布内容:${_controller .text }' );
185
+ bool isSendSuccess = await model.setIssueComment (
186
+ _controller.text,
187
+ issuesContent.number
188
+ );
189
+ if (isSendSuccess) {
190
+ await this ._getIssueComment (context);
191
+ _controller.text = '' ;
192
+ } else {
193
+ print ('网络错误' );
194
+ Scaffold .of (context).showSnackBar (SnackBar (
195
+ content: Text ('网络出错,请稍后重试' ),
196
+ ));
197
+ }
198
+ } else {
199
+ print ('去往登陆' );
200
+ Navigator .of (context).push (
201
+ MaterialPageRoute (
202
+ builder: (BuildContext context) {
203
+ return LoginIndex .Index ();
204
+ }
205
+ )
206
+ );
207
+ }
208
+ }
209
+ },
210
+ child: Container (
211
+ padding: EdgeInsets .fromLTRB (0 , 0 , 10 , 0 ),
212
+ child: Text (
213
+ '发布' ,
214
+ style: TextStyle (
215
+ color: isCanSend ? Theme .of (context).primaryColor : Colors .grey,
216
+ fontSize: 17
217
+ )
218
+ ),
219
+ ),
220
+ );
221
+ }
222
+ )
223
+ ],
224
+ )
225
+ ),
226
+ );
227
+ }
228
+ Widget _InputBox () {
229
+ return Container (
230
+ height: 30 ,
231
+ margin: EdgeInsets .fromLTRB (10 , 10 , 10 , 10 ),
232
+ decoration: BoxDecoration (
233
+ color: Color (int .parse ('0xffEDEDED' )),
234
+ borderRadius: BorderRadius .circular (15 )
235
+ ),
236
+ child: Row (
237
+ children: < Widget > [
238
+ Expanded (
239
+ flex: 1 ,
240
+ child: TextField (
241
+ controller: _controller,
242
+ autofocus: false ,
243
+ onChanged: _onChanged,
244
+ style: TextStyle (
245
+ fontSize: 18.0 ,
246
+ color: Colors .black,
247
+ fontWeight: FontWeight .w300
248
+ ),
249
+ decoration: InputDecoration (
250
+ contentPadding: EdgeInsets .fromLTRB (10 , 0 , 10 , 0 ),
251
+ border: InputBorder .none,
252
+ hintText: '说点什么吧' ,
253
+ hintStyle: TextStyle (fontSize: 15 )
254
+ ),
255
+ ),
256
+ )
257
+ ],
258
+ )
259
+ );
260
+ }
261
+
262
+ _onChanged (String text) {
263
+ if (text.length > 0 ) {
264
+ setState (() {
265
+ isCanSend = true ;
266
+ });
267
+ } else {
268
+ setState (() {
269
+ isCanSend = false ;
270
+ });
271
+ }
272
+ }
273
+ }
0 commit comments