You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
5.8 KiB
176 lines
5.8 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/article.dart'; |
|
import 'package:huixiang/retrofit/data/banner.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/page.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/classic_header.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:huixiang/view_widget/hot_item.dart'; |
|
import 'package:huixiang/view_widget/my_appbar.dart'; |
|
import 'package:huixiang/view_widget/my_footer.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
class ArticleList extends StatefulWidget { |
|
final List<Article> articles; |
|
|
|
ArticleList(this.articles,); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _ArticleList(); |
|
} |
|
} |
|
|
|
class _ArticleList extends State<ArticleList> { |
|
ApiService apiService; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
|
|
SharedPreferences.getInstance().then((value) => { |
|
apiService = ApiService(Dio(), |
|
context: context, token: value.getString("token")), |
|
}); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Container( |
|
margin: EdgeInsets.only(top:20,left:16,right: 16), |
|
child:Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
children: [ |
|
Padding(padding:EdgeInsets.only(bottom: 12), |
|
child:Text( |
|
"最新文章", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 2, |
|
style: TextStyle( |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.black, |
|
), |
|
)), |
|
ListView.builder( |
|
padding: EdgeInsets.zero, |
|
itemCount: widget.articles.length, |
|
scrollDirection: Axis.vertical, |
|
shrinkWrap: true, |
|
physics: NeverScrollableScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () { |
|
Navigator.of(context).pushNamed( |
|
'/router/web_page', |
|
arguments: {"articleId": widget.articles[position].id}); |
|
widget.articles[position].viewers = (widget.articles[position].viewers + 1); |
|
setState(() {}); |
|
}, |
|
child: articleItem(widget.articles[position],position), |
|
); |
|
}, |
|
), |
|
], |
|
)); |
|
} |
|
|
|
Widget articleItem(Article articles,position) { |
|
return Container( |
|
width: double.infinity, |
|
padding: EdgeInsets.all(16), |
|
margin: EdgeInsets.only(bottom: 12), |
|
color: Colors.white, |
|
child:Row( |
|
children: [ |
|
Expanded(child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
children: [ |
|
Text( |
|
widget?.articles[position]?.mainTitle ?? "", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.black, |
|
), |
|
), |
|
SizedBox(height:5), |
|
Text( |
|
widget?.articles[position]?.viceTitle ?? "", |
|
// overflow: TextOverflow.ellipsis, |
|
// maxLines: 1, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
SizedBox(height: 10), |
|
Row( |
|
children: [ |
|
Text( |
|
(widget.articles[position] != null && |
|
widget.articles[position].author != null) |
|
? widget.articles[position].author.name |
|
: "", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Color(0xFF8E8E8E), |
|
), |
|
), |
|
SizedBox(width:8), |
|
Image.asset( |
|
"assets/image/browse.png", |
|
width: 14, |
|
height: 14, |
|
color: Color(0xFF808080), |
|
), |
|
Expanded(child: Text( |
|
"${widget?.articles[position]?.viewers}" |
|
?? "", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF8D8D8D), |
|
), |
|
)), |
|
Text( |
|
widget?.articles[position]?.createTime?.split(" ")[0] |
|
?? "", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF8D8D8D), |
|
), |
|
), |
|
], |
|
), |
|
], |
|
),), |
|
SizedBox(width:12), |
|
MImage( |
|
widget?.articles[position]?.coverImg ?? "", |
|
fit: BoxFit.cover, |
|
radius: BorderRadius.all(Radius.circular(2)), |
|
width:96, |
|
height:96, |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
}
|
|
|