Skip to content

Commit 18a0940

Browse files
author
罗国雄
committed
完成专题详情页
1 parent a91fbe6 commit 18a0940

File tree

4 files changed

+252
-10
lines changed

4 files changed

+252
-10
lines changed

lib/router/index.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import './tipicDetail/index.dart';
1212
import './search/index.dart';
1313
import './noFound.dart';
1414
import './login/index.dart';
15+
import './writeComment/index.dart';
16+
import './moreComment/index.dart';
1517
import 'package:easy_market/page/index.dart';
1618

1719
class Router {
@@ -24,6 +26,9 @@ class Router {
2426
'/home': (context) => Page(),
2527
'/login': (context) => Login(),
2628
'/brand': (context, {arguments}) => Brand(arguments: arguments),
29+
'/writeComment': (context, {arguments}) =>
30+
WriteComment(arguments: arguments),
31+
'/moreComment': (context, {arguments}) => MoreComment(arguments: arguments),
2732
};
2833

2934
// 路由初始化

lib/router/moreComment/index.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @Description: 写评论
3+
* @Author: luoguoxiong
4+
* @Date: 2019-09-05 17:16:00
5+
*/
6+
7+
import 'package:flutter/material.dart';
8+
9+
class MoreComment extends StatefulWidget {
10+
MoreComment({this.arguments});
11+
final Map arguments;
12+
@override
13+
State<StatefulWidget> createState() {
14+
return _MoreComment();
15+
}
16+
}
17+
18+
class _MoreComment extends State<MoreComment> {
19+
@override
20+
Widget build(BuildContext context) {
21+
return Material(
22+
child: Center(
23+
child: Text('更多评论!'),
24+
),
25+
);
26+
}
27+
}

lib/router/tipicDetail/index.dart

Lines changed: 193 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
import 'package:cached_network_image/cached_network_image.dart';
88
import 'package:flutter/material.dart';
9+
import 'package:provider/provider.dart';
10+
import 'package:easy_market/model/index.dart';
911
import 'package:easy_market/component/linearBar.dart';
1012
import 'package:easy_market/api/index.dart';
13+
import 'package:easy_market/utils/rem.dart';
14+
import 'package:easy_market/router/index.dart';
1115

1216
class TopicDetail extends StatefulWidget {
1317
TopicDetail({this.arguments});
@@ -18,6 +22,7 @@ class TopicDetail extends StatefulWidget {
1822
}
1923
}
2024

25+
// 正则太菜,先勉强用着。。。
2126
List getImgUrl(String str) {
2227
var newString = str.replaceAll('<img src=\"', '');
2328
var list = newString.split('">\n ');
@@ -39,6 +44,10 @@ class _TopicDetail extends State<TopicDetail> {
3944
String title;
4045
List content;
4146

47+
List comment;
48+
49+
int commentCount = 0;
50+
4251
@override
4352
void initState() {
4453
super.initState();
@@ -50,16 +59,198 @@ class _TopicDetail extends State<TopicDetail> {
5059
var data = await Future.wait([
5160
Api.getTopicMsg(id: id),
5261
Api.getTopicComment(valueId: id, typeId: 1, page: 1, size: 5),
53-
Api.getRelatedTopic(id: id),
5462
]);
5563
var topicMsg = data[0].data;
64+
var commentMsg = data[1].data;
5665
setState(() {
5766
initLoading = false;
5867
title = topicMsg['title'];
5968
content = getImgUrl(topicMsg['content']);
69+
comment = commentMsg['data'];
70+
commentCount = commentMsg['count'];
6071
});
6172
}
6273

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+
63254
SliverList buildDes() {
64255
return new SliverList(
65256
delegate: new SliverChildBuilderDelegate(
@@ -96,15 +287,7 @@ class _TopicDetail extends State<TopicDetail> {
96287
return LinearBar(
97288
child: CustomScrollView(slivers: [
98289
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(),
108291
]),
109292
removePadding: true,
110293
title: '$title',

lib/router/writeComment/index.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @Description: 写评论
3+
* @Author: luoguoxiong
4+
* @Date: 2019-09-05 17:16:00
5+
*/
6+
7+
import 'package:flutter/material.dart';
8+
9+
class WriteComment extends StatefulWidget {
10+
WriteComment({this.arguments});
11+
final Map arguments;
12+
@override
13+
State<StatefulWidget> createState() {
14+
return _WriteComment();
15+
}
16+
}
17+
18+
class _WriteComment extends State<WriteComment> {
19+
@override
20+
Widget build(BuildContext context) {
21+
return Material(
22+
child: Center(
23+
child: Text('写评论'),
24+
),
25+
);
26+
}
27+
}

0 commit comments

Comments
 (0)