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.
479 lines
20 KiB
479 lines
20 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/article.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/headlines_list.dart'; |
|
import 'package:huixiang/retrofit/data/headlines_list_details.dart'; |
|
import 'package:huixiang/retrofit/data/page.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/view_widget/classic_header.dart'; |
|
import 'package:huixiang/view_widget/custom_image.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'; |
|
|
|
class HeadlinesColumnDetails extends StatefulWidget { |
|
final Map<String, dynamic> arguments; |
|
|
|
HeadlinesColumnDetails({this.arguments}); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _HeadlinesColumnDetails(); |
|
} |
|
} |
|
|
|
class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails> |
|
with WidgetsBindingObserver { |
|
ApiService apiService; |
|
List<Article> articles = []; |
|
HeadlinesListDetails headlinesListDetails; |
|
List<HeadlinesList> headlines = []; |
|
final RefreshController refreshController = RefreshController(); |
|
final ScrollController scrollController = ScrollController(); |
|
int pageNum = 1; |
|
var isShowMore = false; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
WidgetsBinding.instance.addObserver(this); |
|
_onRefresh(); |
|
} |
|
|
|
///文章合集详情 |
|
queryHeadlinesDetails(id) async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
BaseData<HeadlinesListDetails> baseData = |
|
await apiService.headlinesDetails(id).catchError((error) {}); |
|
if (baseData != null && baseData.isSuccess) { |
|
setState(() { |
|
headlinesListDetails = baseData.data; |
|
}); |
|
} |
|
} |
|
|
|
///文章列表 |
|
queryArticleList(categoryId) async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
BaseData<PageInfo<Article>> baseData = await apiService.queryArticle({ |
|
"pageNum": pageNum, |
|
"pageSize": 10, |
|
"searchKey": "", |
|
"state": 1, |
|
"type": 2, |
|
"categoryId": categoryId, |
|
"isHot": false, |
|
}).catchError((onError) { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
}); |
|
if (baseData != null && baseData.isSuccess) { |
|
refreshController.refreshCompleted(); |
|
refreshController.loadComplete(); |
|
if (pageNum == 1) { |
|
articles.clear(); |
|
} |
|
articles.addAll(baseData.data.list); |
|
if (baseData.data.pageNum == baseData.data.pages) { |
|
refreshController.loadNoData(); |
|
} else { |
|
pageNum += 1; |
|
} |
|
setState(() {}); |
|
} else { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
} |
|
} |
|
|
|
_onRefresh() { |
|
queryHeadlinesDetails(widget.arguments["id"]); |
|
queryArticleList(widget.arguments["id"]); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Stack( |
|
children: [ |
|
Positioned( |
|
child: Container( |
|
color: Colors.white, |
|
child: SmartRefresher( |
|
controller: refreshController, |
|
enablePullDown: true, |
|
enablePullUp: true, |
|
header: MyHeader(), |
|
footer: CustomFooter( |
|
builder: (context, mode) { |
|
return MyFooter(mode); |
|
}, |
|
), |
|
onRefresh: _onRefresh, |
|
onLoading: () { |
|
_onRefresh(); |
|
}, |
|
physics: BouncingScrollPhysics(), |
|
scrollController: scrollController, |
|
child: Container( |
|
child: SingleChildScrollView( |
|
physics: BouncingScrollPhysics(), |
|
child: Container( |
|
color: Color(0xFFF7F7F7), |
|
child: Column( |
|
children: [ |
|
Stack( |
|
alignment: Alignment.bottomCenter, |
|
children: [ |
|
Stack( |
|
children: [ |
|
Positioned( |
|
child: Container( |
|
color: Colors.black, |
|
child: Opacity( |
|
opacity: 0.75, |
|
child: MImage( |
|
headlinesListDetails?.bannerImg ?? |
|
"", |
|
width: double.infinity, |
|
height: 260.h, |
|
fit: BoxFit.cover, |
|
errorSrc: |
|
"assets/image/default_1.webp", |
|
fadeSrc: |
|
"assets/image/default_1.webp", |
|
)))), |
|
Container( |
|
margin: EdgeInsets.only( |
|
top: 50.h, left: 16.w, right: 16.w), |
|
decoration: BoxDecoration( |
|
color: Colors.transparent, |
|
), |
|
child: Column( |
|
mainAxisAlignment: |
|
MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: |
|
CrossAxisAlignment.center, |
|
children: [ |
|
GestureDetector( |
|
child: Image.asset( |
|
"assets/image/integral_return.webp", |
|
width: 24, |
|
height: 24, |
|
), |
|
onTap: () { |
|
Navigator.of(context).pop(); |
|
}, |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
Container( |
|
child: Column( |
|
children: [ |
|
Padding( |
|
padding: EdgeInsets.only(left: 16), |
|
child: Row( |
|
children: [ |
|
Container( |
|
margin: EdgeInsets.only(right: 4), |
|
padding: EdgeInsets.only( |
|
left: 2, right: 2), |
|
height: 20.h, |
|
alignment: Alignment.center, |
|
decoration: BoxDecoration( |
|
borderRadius: |
|
BorderRadius.circular(2), |
|
color: Color(0xFF007EFF), |
|
), |
|
child: Text( |
|
S.of(context).zhuanlan, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.white, |
|
), |
|
), |
|
), |
|
SizedBox( |
|
width: 6.w, |
|
), |
|
Expanded( |
|
child: Text( |
|
headlinesListDetails?.name ?? "", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 2, |
|
style: TextStyle( |
|
fontSize: 18.sp, |
|
fontWeight: |
|
MyFontWeight.semi_bold, |
|
color: Colors.white, |
|
), |
|
), |
|
flex: 1, |
|
) |
|
], |
|
), |
|
), |
|
Container( |
|
width: double.infinity, |
|
decoration: BoxDecoration( |
|
border: Border.all( |
|
width: 0, |
|
color: Colors.white, |
|
), |
|
color: Colors.white, |
|
borderRadius: new BorderRadius.only( |
|
topLeft: Radius.circular(8.0), |
|
topRight: Radius.circular(8.0), |
|
), |
|
), |
|
margin: EdgeInsets.only(top: 16), |
|
padding: EdgeInsets.all(16), |
|
child: Column( |
|
children: [ |
|
Row( |
|
mainAxisAlignment: |
|
MainAxisAlignment.start, |
|
crossAxisAlignment: |
|
CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
"简介:", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 2, |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
height: 1.2.h, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.black, |
|
), |
|
), |
|
Expanded(child:Text( |
|
headlinesListDetails |
|
?.introduce ?? |
|
"", |
|
overflow: isShowMore |
|
? TextOverflow.visible |
|
: TextOverflow.ellipsis, |
|
maxLines: isShowMore ? 10 : 2, |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
height: 1.2.h, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.black, |
|
), |
|
),) |
|
], |
|
), |
|
SizedBox(height: 3.h), |
|
GestureDetector( |
|
onTap: () { |
|
setState(() { |
|
isShowMore = !isShowMore; |
|
}); |
|
}, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.end, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
mainAxisSize: MainAxisSize.max, |
|
children: [ |
|
Text( |
|
S.of(context).gengduo, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Colors.black, |
|
), |
|
), |
|
Icon( |
|
(isShowMore != null && !isShowMore) |
|
? Icons.chevron_right |
|
: Icons.keyboard_arrow_up, |
|
color: Colors.black, |
|
size: 18, |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
ListView.builder( |
|
padding: EdgeInsets.zero, |
|
itemCount: articles == null ? 0 : articles.length, |
|
scrollDirection: Axis.vertical, |
|
shrinkWrap: true, |
|
physics: NeverScrollableScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () { |
|
Navigator.of(context) |
|
.pushNamed('/router/web_page', arguments: { |
|
"articleId": articles[position].id |
|
}); |
|
articles[position].viewers = |
|
(articles[position].viewers + 1); |
|
setState(() {}); |
|
}, |
|
child: articleColumnItem(articles[position]), |
|
); |
|
}, |
|
), |
|
], |
|
), |
|
), |
|
), |
|
), |
|
), |
|
), |
|
bottom: 0, |
|
top: 0, |
|
left: 0, |
|
right: 0, |
|
), |
|
], |
|
); |
|
} |
|
|
|
Widget articleColumn() { |
|
return Container(); |
|
} |
|
|
|
Widget articleColumnItem(Article articles) { |
|
return Container( |
|
width: double.infinity, |
|
// padding: EdgeInsets.all(16), |
|
color: Colors.white, |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
children: [ |
|
Container( |
|
// margin: EdgeInsets.only(top: 16,bottom: 16), |
|
width: double.infinity, |
|
height: 0.5.h, |
|
color: Color(0xFFF5F5F5), |
|
), |
|
Padding( |
|
padding: EdgeInsets.all(16), |
|
child: Row( |
|
children: [ |
|
Expanded( |
|
child: Container( |
|
height: |
|
MediaQuery.of(context).size.width >= 650 ? 133.h : 105, |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
children: [ |
|
Text( |
|
articles?.mainTitle ?? "", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 2, |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
height: 1.2.h, |
|
fontWeight: MyFontWeight.medium, |
|
color: Colors.black, |
|
), |
|
), |
|
SizedBox(height: 6.h), |
|
Expanded( |
|
child: Text( |
|
articles?.viceTitle ?? "", |
|
overflow: TextOverflow.ellipsis, |
|
maxLines: 1, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
height: 1.2.h, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF353535), |
|
), |
|
)), |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
// Expanded( |
|
// child: Text( |
|
// articles?.author?.name ?? "", |
|
// overflow: TextOverflow.ellipsis, |
|
// maxLines: 1, |
|
// style: TextStyle( |
|
// fontSize: 12.sp, |
|
// fontWeight: MyFontWeight.medium, |
|
// color: Color(0xFF8E8E8E), |
|
// ), |
|
// ), |
|
// ), |
|
// SizedBox(width: 8), |
|
Image.asset( |
|
"assets/image/browse.webp", |
|
width: 14, |
|
height: 14, |
|
color: Color(0xFF808080), |
|
), |
|
Expanded( |
|
child: Text( |
|
"${articles?.viewers}" ?? "", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF8D8D8D), |
|
), |
|
)), |
|
Expanded(child: |
|
Text( |
|
articles?.createTime?.split(":")[0] ?? "", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF8D8D8D), |
|
), |
|
),) |
|
], |
|
), |
|
], |
|
), |
|
)), |
|
SizedBox(width: 12.w), |
|
MImage( |
|
articles?.coverImg ?? "", |
|
fit: BoxFit.cover, |
|
radius: BorderRadius.all(Radius.circular(2)), |
|
width: 100, |
|
height: 100, |
|
), |
|
], |
|
)), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|