import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.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 arguments; HeadlinesColumnDetails({this.arguments}); @override State createState() { return _HeadlinesColumnDetails(); } } class _HeadlinesColumnDetails extends State with WidgetsBindingObserver { ApiService apiService; List
articles = []; HeadlinesListDetails headlinesListDetails; List headlines = []; final RefreshController refreshController = RefreshController(); final ScrollController scrollController = ScrollController(); int pageNum = 1; @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 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> 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.png", fadeSrc: "assets/image/default_1.png", ) ) ) ), 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.png", 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( "专栏", 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( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: EdgeInsets.all(16), child: Text( "简介:${headlinesListDetails?.introduce ?? ""}", overflow: TextOverflow.ellipsis, maxLines: 2, style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.medium, color: Colors.black, ), )), ], ), ), ], ), ), ], ), 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( 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: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text( articles?.mainTitle ?? "", overflow: TextOverflow.ellipsis, maxLines: 1, style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.medium, color: Colors.black, ), ), SizedBox(height: 5), Text( articles?.viceTitle ?? "", // overflow: TextOverflow.ellipsis, // maxLines: 1, style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF353535), ), ), SizedBox(height: 10), Row( 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.png", width: 14, height: 14, color: Color(0xFF808080), ), Expanded( child: Text( "${articles?.viewers}" ?? "", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF8D8D8D), ), )), Text( articles?.createTime ?? "", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF8D8D8D), ), ), ], ), ], ), ), SizedBox(width: 12), MImage( articles?.coverImg ?? "", fit: BoxFit.cover, radius: BorderRadius.all(Radius.circular(2)), width: 96, height: 96, ), ], )), ], ), ); } }