@@ -12,144 +12,173 @@ import 'package:flutter_wanandroid/model/route_page_data.dart';
12
12
import 'package:flutter_wanandroid/res/colours.dart' ;
13
13
import 'package:flutter_wanandroid/routers/routes.dart' ;
14
14
import 'package:flutter_wanandroid/utils/tool_utils.dart' ;
15
- import 'package:flutter_wanandroid/widget/stroke_widget.dart' ;
16
-
17
15
18
16
class ListViewItem extends StatefulWidget {
19
-
20
-
21
17
final ArticleData articleData;
22
18
final bool isHomeShow; // 是否首页展示 控制 是否还能点击 进入知识体系
23
19
final bool isClickUser; // 是可以点击作者 跳转对应页面
24
20
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);
27
27
28
28
@override
29
29
_ListViewItemState createState () => _ListViewItemState ();
30
30
}
31
31
32
32
class _ListViewItemState extends State <ListViewItem > {
33
-
34
-
35
-
36
33
@override
37
34
Widget build (BuildContext context) {
38
35
return new Card (
39
- color: dataUtils.getIsDarkMode () ? Colours .dark_material_bg : Colors .white,
36
+ color:
37
+ dataUtils.getIsDarkMode () ? Colours .dark_material_bg : Colors .white,
40
38
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 ),
42
40
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 )}' );
46
51
},
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 ),
49
61
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
+ ),
61
73
),
74
+ subtitle: Row (children: _setArticleWidget (widget.articleData)),
62
75
),
63
76
);
64
77
}
65
78
66
-
67
79
//返回 list 集合 显示文章信息
68
80
List <Widget > _setArticleWidget (ArticleData articleData) {
69
- List < Widget > widget = [];
70
- if (1 == articleData.type){
81
+ List <Widget > widget = [];
82
+ if (1 == articleData.type) {
71
83
// 加入 置顶标签
72
- widget.add ( ToolUtils .buildStrokeWidget ('置顶' ,Colors .redAccent));
84
+ widget.add (ToolUtils .buildStrokeWidget ('置顶' , Colors .redAccent));
73
85
}
74
- if (articleData.fresh){
86
+ if (articleData.fresh) {
75
87
//加入 新 标签
76
- widget.add ( ToolUtils .buildStrokeWidget ('新' ,Colors .redAccent));
88
+ widget.add (ToolUtils .buildStrokeWidget ('新' , Colors .redAccent));
77
89
}
78
- if (articleData.tags.length > 0 ){
90
+ if (articleData.tags.length > 0 ) {
79
91
//加入 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));
82
94
});
83
95
}
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 (
86
100
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 {
94
117
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 )}' );
96
120
}
97
121
}
98
122
},
99
123
),
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 ),
109
125
));
110
126
widget.add (Expanded (
111
127
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,
115
144
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),
117
149
overflow: TextOverflow .ellipsis,
118
150
),
119
- onTap: (){
120
- if (this .widget.isHomeShow){
151
+ onTap: () {
152
+ if (this .widget.isHomeShow) {
121
153
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 )}' );
123
156
}
124
157
},
125
- )
126
158
)));
127
159
return widget;
128
160
}
129
161
130
162
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: "请先登录" );
134
166
return ;
135
167
}
136
- if (widget.articleData.collect){
168
+ if (widget.articleData.collect) {
137
169
//取消收藏
138
170
await dataUtils.getCancelCollectInnerArticle (widget.articleData.id);
139
171
setState (() {
140
172
widget.articleData.collect = false ;
141
173
});
142
- ToolUtils .showToast (msg: "取消收藏成功" );
143
- }else {
174
+ ToolUtils .showToast (msg: "取消收藏成功" );
175
+ } else {
144
176
//添加收藏
145
177
await dataUtils.getCollectInnerArticle (widget.articleData.id);
146
178
setState (() {
147
179
widget.articleData.collect = true ;
148
180
});
149
- ToolUtils .showToast (msg: "收藏成功" );
181
+ ToolUtils .showToast (msg: "收藏成功" );
150
182
}
151
183
}
152
-
153
184
}
154
-
155
-
0 commit comments