|
|
@ -6,10 +6,13 @@ import 'package:huixiang/retrofit/data/article.dart'; |
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
|
|
import 'package:huixiang/retrofit/data/headlines_list.dart'; |
|
|
|
import 'package:huixiang/retrofit/data/headlines_list.dart'; |
|
|
|
import 'package:huixiang/retrofit/data/headlines_list_details.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/retrofit/retrofit_api.dart'; |
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.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/custom_image.dart'; |
|
|
|
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class HeadlinesColumnDetails extends StatefulWidget { |
|
|
|
class HeadlinesColumnDetails extends StatefulWidget { |
|
|
@ -29,14 +32,17 @@ class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails> |
|
|
|
List<Article> articles; |
|
|
|
List<Article> articles; |
|
|
|
HeadlinesListDetails headlinesListDetails; |
|
|
|
HeadlinesListDetails headlinesListDetails; |
|
|
|
List<HeadlinesList> headlines = []; |
|
|
|
List<HeadlinesList> headlines = []; |
|
|
|
|
|
|
|
final RefreshController refreshController = RefreshController(); |
|
|
|
|
|
|
|
int pageNum = 1; |
|
|
|
|
|
|
|
final ScrollController scrollController = ScrollController(); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
super.initState(); |
|
|
|
articles = widget.arguments["articles"]; |
|
|
|
articles = widget.arguments["articles"]; |
|
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
queryHeadlinesDetails(widget.arguments["id"]); |
|
|
|
queryHeadlinesDetails(widget.arguments["categoryId"]); |
|
|
|
queryHeadlinesList(widget.arguments["id"]); |
|
|
|
queryArticleList(widget.arguments["categoryId"]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
///文章合集详情 |
|
|
|
///文章合集详情 |
|
|
@ -58,8 +64,8 @@ class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails> |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
///文章合集列表 |
|
|
|
///文章列表 |
|
|
|
queryHeadlinesList(id) async { |
|
|
|
queryArticleList(categoryId) async { |
|
|
|
if (apiService == null) { |
|
|
|
if (apiService == null) { |
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
apiService = ApiService( |
|
|
|
apiService = ApiService( |
|
|
@ -68,24 +74,54 @@ class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails> |
|
|
|
token: value.getString("token"), |
|
|
|
token: value.getString("token"), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
BaseData<List<HeadlinesList>> baseData = await apiService.headlinesList().catchError((onError) {}); |
|
|
|
BaseData<PageInfo<Article>> baseData = await apiService.queryArticle({ |
|
|
|
|
|
|
|
"pageNum": pageNum, |
|
|
|
|
|
|
|
"pageSize": 10, |
|
|
|
|
|
|
|
"searchKey": "", |
|
|
|
|
|
|
|
"state": 1, |
|
|
|
|
|
|
|
"type": 2, |
|
|
|
|
|
|
|
"categoryId":widget.arguments["categoryId"] |
|
|
|
|
|
|
|
}).catchError((onError){ |
|
|
|
|
|
|
|
refreshController.refreshFailed(); |
|
|
|
|
|
|
|
refreshController.loadFailed(); |
|
|
|
|
|
|
|
}); |
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
setState(() { |
|
|
|
refreshController.refreshCompleted(); |
|
|
|
headlines.clear(); |
|
|
|
refreshController.loadComplete(); |
|
|
|
headlines.addAll(baseData.data); |
|
|
|
if(pageNum == 1) { |
|
|
|
headlines.forEach((element) { |
|
|
|
articles.clear(); |
|
|
|
// collectCourse(element.id); |
|
|
|
} |
|
|
|
}); |
|
|
|
articles.addAll(baseData.data.list); |
|
|
|
}); |
|
|
|
if (baseData.data.pageNum == baseData.data.pages) { |
|
|
|
|
|
|
|
refreshController.loadNoData(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pageNum += 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setState(() {}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
refreshController.refreshFailed(); |
|
|
|
|
|
|
|
refreshController.loadFailed(); |
|
|
|
} |
|
|
|
} |
|
|
|
EasyLoading.dismiss(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_onRefresh(){ |
|
|
|
|
|
|
|
queryHeadlinesDetails(widget.arguments["categoryId"]); |
|
|
|
|
|
|
|
queryArticleList(widget.arguments["categoryId"]);//分类列表 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Scaffold( |
|
|
|
return Scaffold( |
|
|
|
body: Container( |
|
|
|
body: Container( |
|
|
|
child: Column( |
|
|
|
child: SmartRefresher( |
|
|
|
|
|
|
|
controller: refreshController, |
|
|
|
|
|
|
|
enablePullDown: true, |
|
|
|
|
|
|
|
enablePullUp: false, |
|
|
|
|
|
|
|
header: MyHeader(), |
|
|
|
|
|
|
|
physics: ClampingScrollPhysics(), |
|
|
|
|
|
|
|
onRefresh: _onRefresh, |
|
|
|
|
|
|
|
scrollController: scrollController, |
|
|
|
|
|
|
|
child:Column( |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
Expanded( |
|
|
|
child: SingleChildScrollView( |
|
|
|
child: SingleChildScrollView( |
|
|
@ -215,7 +251,7 @@ class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails> |
|
|
|
), |
|
|
|
), |
|
|
|
ListView.builder( |
|
|
|
ListView.builder( |
|
|
|
padding: EdgeInsets.zero, |
|
|
|
padding: EdgeInsets.zero, |
|
|
|
itemCount:headlines == null ? 0 : headlines.length, |
|
|
|
itemCount:articles.length, |
|
|
|
scrollDirection: Axis.vertical, |
|
|
|
scrollDirection: Axis.vertical, |
|
|
|
shrinkWrap: true, |
|
|
|
shrinkWrap: true, |
|
|
|
physics: NeverScrollableScrollPhysics(), |
|
|
|
physics: NeverScrollableScrollPhysics(), |
|
|
@ -240,7 +276,7 @@ class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails> |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
),) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -289,10 +325,7 @@ class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails> |
|
|
|
Row( |
|
|
|
Row( |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
Text( |
|
|
|
(articles != null && |
|
|
|
articles?.author?.name ?? "", |
|
|
|
articles.author != null) |
|
|
|
|
|
|
|
? articles.author.name |
|
|
|
|
|
|
|
: "", |
|
|
|
|
|
|
|
style: TextStyle( |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 12.sp, |
|
|
|
fontSize: 12.sp, |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|