Skip to content

Commit 8bbcaaa

Browse files
committed
solve article item bug
1 parent b2dd33f commit 8bbcaaa

File tree

1 file changed

+102
-73
lines changed

1 file changed

+102
-73
lines changed

flutter_wanandroid/lib/views/home/item/list_view_item.dart

Lines changed: 102 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,144 +12,173 @@ import 'package:flutter_wanandroid/model/route_page_data.dart';
1212
import 'package:flutter_wanandroid/res/colours.dart';
1313
import 'package:flutter_wanandroid/routers/routes.dart';
1414
import 'package:flutter_wanandroid/utils/tool_utils.dart';
15-
import 'package:flutter_wanandroid/widget/stroke_widget.dart';
16-
1715

1816
class ListViewItem extends StatefulWidget {
19-
20-
2117
final ArticleData articleData;
2218
final bool isHomeShow; // 是否首页展示 控制 是否还能点击 进入知识体系
2319
final bool isClickUser; // 是可以点击作者 跳转对应页面
2420

25-
const ListViewItem({Key key, this.articleData,this.isHomeShow = true, this.isClickUser=true})
26-
:super(key:key);
21+
const ListViewItem(
22+
{Key key,
23+
this.articleData,
24+
this.isHomeShow = true,
25+
this.isClickUser = true})
26+
: super(key: key);
2727

2828
@override
2929
_ListViewItemState createState() => _ListViewItemState();
3030
}
3131

3232
class _ListViewItemState extends State<ListViewItem> {
33-
34-
35-
3633
@override
3734
Widget build(BuildContext context) {
3835
return new Card(
39-
color: dataUtils.getIsDarkMode() ? Colours.dark_material_bg : Colors.white,
36+
color:
37+
dataUtils.getIsDarkMode() ? Colours.dark_material_bg : Colors.white,
4038
elevation: 4.0,
41-
margin: new EdgeInsets.symmetric(horizontal: 10.0,vertical: 6.0),
39+
margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
4240
child: ListTile(
43-
onTap: (){ //link 跳转 webview
44-
RoutePageData routePageData = new RoutePageData(widget.articleData.id, widget.articleData.title, widget.articleData.link,Constants.COLLECT_PAGE_TYPE , widget.articleData.collect);
45-
Application.router.navigateTo(context, '${Routes.webViewPage}?routePageJson=${ToolUtils.object2string(routePageData)}');
41+
onTap: () {
42+
//link 跳转 webview
43+
RoutePageData routePageData = new RoutePageData(
44+
widget.articleData.id,
45+
widget.articleData.title,
46+
widget.articleData.link,
47+
Constants.COLLECT_PAGE_TYPE,
48+
widget.articleData.collect);
49+
Application.router.navigateTo(context,
50+
'${Routes.webViewPage}?routePageJson=${ToolUtils.object2string(routePageData)}');
4651
},
47-
leading: IconButton(icon: new Icon(widget.articleData.collect ? Icons.favorite : Icons.favorite_border,
48-
color: widget.articleData.collect ? Colors.deepOrange : Colors.grey, size: 25.0),
52+
leading: IconButton(
53+
icon: new Icon(
54+
widget.articleData.collect
55+
? Icons.favorite
56+
: Icons.favorite_border,
57+
color: widget.articleData.collect
58+
? Colors.deepOrange
59+
: Colors.grey,
60+
size: 25.0),
4961
onPressed: _clickCollection),
50-
title: Padding( //文章标题
51-
padding: EdgeInsets.only(top: 10.0,bottom: 10.0),
52-
child: Text(
53-
ToolUtils.signToStr(widget.articleData.title),
54-
style: TextStyle(color: Colors.black, fontSize: 15.0,fontWeight: FontWeight.bold),
55-
maxLines: 1, // title 只显示一行
56-
overflow: TextOverflow.ellipsis //超出一行 显示 ...
57-
),
58-
),
59-
subtitle: Row(
60-
children: _setArticleWidget(widget.articleData)
62+
title: Padding(
63+
//文章标题
64+
padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
65+
child: Text(ToolUtils.signToStr(widget.articleData.title),
66+
style: TextStyle(
67+
color: Colors.black,
68+
fontSize: 15.0,
69+
fontWeight: FontWeight.bold),
70+
maxLines: 1, // title 只显示一行
71+
overflow: TextOverflow.ellipsis //超出一行 显示 ...
72+
),
6173
),
74+
subtitle: Row(children: _setArticleWidget(widget.articleData)),
6275
),
6376
);
6477
}
6578

66-
6779
//返回 list 集合 显示文章信息
6880
List<Widget> _setArticleWidget(ArticleData articleData) {
69-
List <Widget> widget = [];
70-
if(1 == articleData.type){
81+
List<Widget> widget = [];
82+
if (1 == articleData.type) {
7183
// 加入 置顶标签
72-
widget.add( ToolUtils.buildStrokeWidget('置顶',Colors.redAccent));
84+
widget.add(ToolUtils.buildStrokeWidget('置顶', Colors.redAccent));
7385
}
74-
if(articleData.fresh){
86+
if (articleData.fresh) {
7587
//加入 新 标签
76-
widget.add( ToolUtils.buildStrokeWidget('新',Colors.redAccent));
88+
widget.add(ToolUtils.buildStrokeWidget('新', Colors.redAccent));
7789
}
78-
if(articleData.tags.length > 0){
90+
if (articleData.tags.length > 0) {
7991
//加入 tag 标签
80-
articleData.tags.forEach((tag){
81-
widget.add( ToolUtils.buildStrokeWidget(tag.name,Colors.green));
92+
articleData.tags.forEach((tag) {
93+
widget.add(ToolUtils.buildStrokeWidget(tag.name, Colors.green));
8294
});
8395
}
84-
widget.add(new Icon(articleData.author == ""?Icons.folder_shared:Icons.person,size: 20.0));
85-
widget.add( Padding(
96+
widget.add(new Icon(
97+
articleData.author == "" ? Icons.folder_shared : Icons.person,
98+
size: 20.0));
99+
widget.add(Padding(
86100
child: InkWell(
87-
child: Text(articleData.author == ""? articleData.shareUser :articleData.author,
88-
style: TextStyle(color: this.widget.isClickUser? Colors.blue:Colors.black54, fontSize: 10.0)),
89-
onTap: (){
90-
if(this.widget.isClickUser){
91-
if(!(articleData.author == "")){ //如果作者不为空,说明可以根据作者昵称查看文章 否则查看 分享人 个人信息主页
92-
Application.router.navigateTo(context, '${Routes.knowledgedetail}?type=${Uri.encodeComponent(Constants.RESULT_CODE_AUTHOR_ARTICLE_PAGE)}&author=${Uri.encodeComponent(articleData.author)}');
93-
}else{
101+
child: Text(
102+
articleData.author == ""
103+
? articleData.shareUser
104+
: articleData.author,
105+
maxLines: 1, // title 只显示一行
106+
overflow: TextOverflow.ellipsis,
107+
style: TextStyle(
108+
color: this.widget.isClickUser ? Colors.blue : Colors.black54,
109+
fontSize: 10.0)),
110+
onTap: () {
111+
if (this.widget.isClickUser) {
112+
if (!(articleData.author == "")) {
113+
//如果作者不为空,说明可以根据作者昵称查看文章 否则查看 分享人 个人信息主页
114+
Application.router.navigateTo(context,
115+
'${Routes.knowledgedetail}?type=${Uri.encodeComponent(Constants.RESULT_CODE_AUTHOR_ARTICLE_PAGE)}&author=${Uri.encodeComponent(articleData.author)}');
116+
} else {
94117
print("跳转分享人个人中心");
95-
Application.router.navigateTo(context, '${Routes.userCenterPage}?type=${Uri.encodeComponent(Constants.USER_SHARE_CENTER_PAGE_TYPE)}&authorId=${Uri.encodeComponent(articleData.userId.toString())}&authorName=${Uri.encodeComponent(articleData.shareUser)}');
118+
Application.router.navigateTo(context,
119+
'${Routes.userCenterPage}?type=${Uri.encodeComponent(Constants.USER_SHARE_CENTER_PAGE_TYPE)}&authorId=${Uri.encodeComponent(articleData.userId.toString())}&authorName=${Uri.encodeComponent(articleData.shareUser)}');
96120
}
97121
}
98122
},
99123
),
100-
padding: EdgeInsets.only(top: 10.0, bottom: 10.0,left: 5.0),
101-
));
102-
widget.add(Padding(
103-
child: Text('时间:'+articleData.niceDate ,
104-
style: TextStyle(color: Colors.black54, fontSize: 10.0,),
105-
maxLines: 1, // title 只显示一行
106-
overflow: TextOverflow.ellipsis //超出一行 显示 ...
107-
),
108-
padding: EdgeInsets.only(top: 10.0, bottom: 10.0,left: 5.0),
124+
padding: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 5.0),
109125
));
110126
widget.add(Expanded(
111127
child: Padding(
112-
padding: EdgeInsets.only(top: 10.0, bottom: 10.0,left: 10.0),
113-
child: InkWell( //点击水波纹效果
114-
child: Text(articleData.superChapterName+" / "+ articleData.chapterName,
128+
child: Text('时间:' + articleData.niceDate,
129+
style: TextStyle(
130+
color: Colors.black54,
131+
fontSize: 10.0,
132+
),
133+
maxLines: 1, // title 只显示一行
134+
overflow: TextOverflow.ellipsis //超出一行 显示 ...
135+
),
136+
padding: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 5.0),
137+
)));
138+
widget.add(Padding(
139+
padding: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 10.0),
140+
child: InkWell(
141+
//点击水波纹效果
142+
child: Text(
143+
articleData.superChapterName + " / " + articleData.chapterName,
115144
maxLines: 1,
116-
style: TextStyle(color:this.widget.isHomeShow? Colors.blue:Colors.black54, fontSize: 10.0,decoration: TextDecoration.none),
145+
style: TextStyle(
146+
color: this.widget.isHomeShow ? Colors.blue : Colors.black54,
147+
fontSize: 10.0,
148+
decoration: TextDecoration.none),
117149
overflow: TextOverflow.ellipsis,
118150
),
119-
onTap: (){
120-
if(this.widget.isHomeShow){
151+
onTap: () {
152+
if (this.widget.isHomeShow) {
121153
print("跳转 知识体系下文章 ");
122-
Application.router.navigateTo(context,'${Routes.knowledgedetail}?type=${Uri.encodeComponent(Constants.RESULT_CODE_HOME_PAGE)}&articleJson=${ToolUtils.object2string(articleData)}');
154+
Application.router.navigateTo(context,
155+
'${Routes.knowledgedetail}?type=${Uri.encodeComponent(Constants.RESULT_CODE_HOME_PAGE)}&articleJson=${ToolUtils.object2string(articleData)}');
123156
}
124157
},
125-
)
126158
)));
127159
return widget;
128160
}
129161

130162
void _clickCollection() async {
131-
if(!dataUtils.hasLogin()){
132-
Application.router.navigateTo(context,Routes.login);
133-
ToolUtils.showToast(msg:"请先登录");
163+
if (!dataUtils.hasLogin()) {
164+
Application.router.navigateTo(context, Routes.login);
165+
ToolUtils.showToast(msg: "请先登录");
134166
return;
135167
}
136-
if(widget.articleData.collect){
168+
if (widget.articleData.collect) {
137169
//取消收藏
138170
await dataUtils.getCancelCollectInnerArticle(widget.articleData.id);
139171
setState(() {
140172
widget.articleData.collect = false;
141173
});
142-
ToolUtils.showToast(msg:"取消收藏成功");
143-
}else{
174+
ToolUtils.showToast(msg: "取消收藏成功");
175+
} else {
144176
//添加收藏
145177
await dataUtils.getCollectInnerArticle(widget.articleData.id);
146178
setState(() {
147179
widget.articleData.collect = true;
148180
});
149-
ToolUtils.showToast(msg:"收藏成功");
181+
ToolUtils.showToast(msg: "收藏成功");
150182
}
151183
}
152-
153184
}
154-
155-

0 commit comments

Comments
 (0)