6
6
7
7
import 'package:cached_network_image/cached_network_image.dart' ;
8
8
import 'package:flutter/material.dart' ;
9
+ import 'package:provider/provider.dart' ;
10
+ import 'package:easy_market/model/index.dart' ;
9
11
import 'package:easy_market/component/linearBar.dart' ;
10
12
import 'package:easy_market/api/index.dart' ;
13
+ import 'package:easy_market/utils/rem.dart' ;
14
+ import 'package:easy_market/router/index.dart' ;
11
15
12
16
class TopicDetail extends StatefulWidget {
13
17
TopicDetail ({this .arguments});
@@ -18,6 +22,7 @@ class TopicDetail extends StatefulWidget {
18
22
}
19
23
}
20
24
25
+ // 正则太菜,先勉强用着。。。
21
26
List getImgUrl (String str) {
22
27
var newString = str.replaceAll ('<img src=\" ' , '' );
23
28
var list = newString.split ('">\n ' );
@@ -39,6 +44,10 @@ class _TopicDetail extends State<TopicDetail> {
39
44
String title;
40
45
List content;
41
46
47
+ List comment;
48
+
49
+ int commentCount = 0 ;
50
+
42
51
@override
43
52
void initState () {
44
53
super .initState ();
@@ -50,16 +59,198 @@ class _TopicDetail extends State<TopicDetail> {
50
59
var data = await Future .wait ([
51
60
Api .getTopicMsg (id: id),
52
61
Api .getTopicComment (valueId: id, typeId: 1 , page: 1 , size: 5 ),
53
- Api .getRelatedTopic (id: id),
54
62
]);
55
63
var topicMsg = data[0 ].data;
64
+ var commentMsg = data[1 ].data;
56
65
setState (() {
57
66
initLoading = false ;
58
67
title = topicMsg['title' ];
59
68
content = getImgUrl (topicMsg['content' ]);
69
+ comment = commentMsg['data' ];
70
+ commentCount = commentMsg['count' ];
60
71
});
61
72
}
62
73
74
+ toWrite (context) {
75
+ final model = Provider .of <Model >(context);
76
+ if (model.token != null ) {
77
+ Router .push ('/writeComment' , context, {'id' : widget.arguments['id' ]});
78
+ } else {
79
+ Router .push ('/login' , context);
80
+ }
81
+ }
82
+
83
+ buildCommentList () {
84
+ if (comment.length > 0 ) {
85
+ List <Widget > commentList = [];
86
+ for (int i = 0 ; i < comment.length; i++ ) {
87
+ commentList.add (Container (
88
+ padding: EdgeInsets .symmetric (
89
+ horizontal: Rem .getPxToRem (8 ),
90
+ ),
91
+ color: Colors .white,
92
+ child: Container (
93
+ height: Rem .getPxToRem (160 ),
94
+ decoration: BoxDecoration (
95
+ border: Border (
96
+ bottom: BorderSide (width: .6 , color: Colors .grey),
97
+ ),
98
+ ),
99
+ child: Column (
100
+ children: < Widget > [
101
+ Expanded (
102
+ child: Row (
103
+ children: < Widget > [
104
+ Expanded (
105
+ child: Align (
106
+ alignment: Alignment .centerLeft,
107
+ child: Text (
108
+ comment[i]['user_info' ]['username' ] == null
109
+ ? '匿名用户'
110
+ : comment[i]['user_info' ]['username' ]),
111
+ ),
112
+ ),
113
+ Expanded (
114
+ child: Align (
115
+ alignment: Alignment .centerRight,
116
+ child: Text (
117
+ comment[i]['add_time' ],
118
+ style: TextStyle (color: Colors .grey),
119
+ ),
120
+ ),
121
+ )
122
+ ],
123
+ ),
124
+ ),
125
+ Expanded (
126
+ child: Align (
127
+ alignment: Alignment .centerLeft,
128
+ child: Text (
129
+ comment[i]['content' ],
130
+ overflow: TextOverflow .ellipsis,
131
+ style: TextStyle (color: Colors .grey),
132
+ ),
133
+ ),
134
+ )
135
+ ],
136
+ ),
137
+ ),
138
+ ));
139
+ }
140
+ return Column (
141
+ children: commentList,
142
+ );
143
+ } else {
144
+ return Container (
145
+ height: 100 ,
146
+ color: Colors .white,
147
+ child: Center (
148
+ child: Text (
149
+ '留言板空空如也~ ' ,
150
+ style: TextStyle (color: Colors .grey),
151
+ ),
152
+ ),
153
+ );
154
+ }
155
+ }
156
+
157
+ SliverList buildComment () {
158
+ return SliverList (
159
+ delegate: SliverChildBuilderDelegate ((BuildContext context, int index) {
160
+ return Column (
161
+ children: < Widget > [
162
+ Container (
163
+ padding: EdgeInsets .symmetric (
164
+ horizontal: Rem .getPxToRem (8 ),
165
+ ),
166
+ margin: EdgeInsets .only (top: Rem .getPxToRem (20 )),
167
+ color: Colors .white,
168
+ child: Container (
169
+ height: Rem .getPxToRem (100 ),
170
+ decoration: BoxDecoration (
171
+ border: Border (
172
+ bottom: BorderSide (width: .5 , color: Colors .grey),
173
+ ),
174
+ ),
175
+ child: Center (
176
+ child: Text (
177
+ '专题留言' ,
178
+ style: TextStyle (
179
+ color: Colors .green,
180
+ fontSize: Rem .getPxToRem (36 ),
181
+ ),
182
+ ),
183
+ ),
184
+ ),
185
+ ),
186
+ buildCommentList (),
187
+ commentCount > 5
188
+ ? Container (
189
+ color: Colors .white,
190
+ padding: EdgeInsets .symmetric (horizontal: 20 ),
191
+ child: Row (
192
+ children: < Widget > [
193
+ Expanded (
194
+ child: FlatButton (
195
+ color: Colors .lightBlue[200 ],
196
+ highlightColor: Colors .blue[700 ],
197
+ colorBrightness: Brightness .dark,
198
+ splashColor: Colors .grey,
199
+ child: Text ("更多" ),
200
+ shape: RoundedRectangleBorder (
201
+ borderRadius: BorderRadius .circular (5.0 )),
202
+ onPressed: () {
203
+ Router .push ('/moreComment' , context,
204
+ {'id' : widget.arguments['id' ]});
205
+ },
206
+ ),
207
+ ),
208
+ Container (
209
+ width: 20 ,
210
+ ),
211
+ Expanded (
212
+ child: FlatButton (
213
+ color: Colors .lightBlue[200 ],
214
+ highlightColor: Colors .blue[700 ],
215
+ colorBrightness: Brightness .dark,
216
+ splashColor: Colors .grey,
217
+ child: Text ("留言" ),
218
+ shape: RoundedRectangleBorder (
219
+ borderRadius: BorderRadius .circular (5.0 )),
220
+ onPressed: () {
221
+ toWrite (context);
222
+ },
223
+ ),
224
+ ),
225
+ ],
226
+ ),
227
+ )
228
+ : Container (
229
+ color: Colors .white,
230
+ height: Rem .getPxToRem (120 ),
231
+ width: double .infinity,
232
+ padding: EdgeInsets .fromLTRB (
233
+ Rem .getPxToRem (20 ),
234
+ Rem .getPxToRem (8 ),
235
+ Rem .getPxToRem (20 ),
236
+ Rem .getPxToRem (8 )),
237
+ child: FlatButton (
238
+ color: Colors .lightBlue[200 ],
239
+ highlightColor: Colors .blue[700 ],
240
+ colorBrightness: Brightness .dark,
241
+ splashColor: Colors .grey,
242
+ child: Text ("我要留言" ),
243
+ onPressed: () {
244
+ toWrite (context);
245
+ },
246
+ ),
247
+ )
248
+ ],
249
+ );
250
+ }, childCount: 1 ),
251
+ );
252
+ }
253
+
63
254
SliverList buildDes () {
64
255
return new SliverList (
65
256
delegate: new SliverChildBuilderDelegate (
@@ -96,15 +287,7 @@ class _TopicDetail extends State<TopicDetail> {
96
287
return LinearBar (
97
288
child: CustomScrollView (slivers: [
98
289
buildDes (),
99
- SliverList (
100
- delegate: new SliverChildBuilderDelegate (
101
- (BuildContext context, int index) {
102
- return Container (
103
- color: Colors .pink,
104
- );
105
- },
106
- childCount: 1 ,
107
- ))
290
+ buildComment (),
108
291
]),
109
292
removePadding: true ,
110
293
title: '$title ' ,
0 commit comments