|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:huixiang/data/base_data.dart';
|
|
|
|
import 'package:huixiang/data/comunity_comment.dart';
|
|
|
|
import 'package:huixiang/data/page.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/utils/shared_preference.dart';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/my_footer.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
|
|
|
|
import 'community_list.dart';
|
|
|
|
|
|
|
|
class CommunityChildList extends StatefulWidget {
|
|
|
|
final String typeStr;
|
|
|
|
|
|
|
|
CommunityChildList(this.typeStr);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _CommunityChildList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CommunityChildList extends State<CommunityChildList> {
|
|
|
|
RefreshController refreshController = RefreshController();
|
|
|
|
final ScrollController scrollController = ScrollController();
|
|
|
|
ApiService? apiService;
|
|
|
|
int pageNum = 1;
|
|
|
|
String? userId;
|
|
|
|
bool isLoadMore = false;
|
|
|
|
|
|
|
|
List<ComunityComment> comments = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
apiService = ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: SharedInstance.instance.token,
|
|
|
|
);
|
|
|
|
_onRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
_onRefresh() async {
|
|
|
|
queryCommunity();
|
|
|
|
}
|
|
|
|
|
|
|
|
///动态列表
|
|
|
|
queryCommunity() async {
|
|
|
|
if(isLoadMore){
|
|
|
|
pageNum += 1;
|
|
|
|
isLoadMore = false;
|
|
|
|
} else {
|
|
|
|
pageNum = 1;
|
|
|
|
}
|
|
|
|
BaseData<PageInfo<ComunityComment>>? baseData = await apiService?.trendList({
|
|
|
|
"onlyFollow": widget.typeStr == "关注" ? true : false,
|
|
|
|
"onlyMe": false,
|
|
|
|
"pageNum": pageNum,
|
|
|
|
"pageSize": 10,
|
|
|
|
"searchKey": ""
|
|
|
|
}).catchError((error) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
refreshController.loadFailed();
|
|
|
|
return BaseData<PageInfo<ComunityComment>>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
refreshController.refreshCompleted();
|
|
|
|
refreshController.loadComplete();
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
setState(() {
|
|
|
|
if (pageNum == 1) {
|
|
|
|
comments.clear();
|
|
|
|
}
|
|
|
|
comments.addAll(baseData?.data?.list ?? []);
|
|
|
|
// comments.sort((a,b)=>b.createTime.compareTo(a.createTime));
|
|
|
|
// print("comments: ${comments.length}");
|
|
|
|
if ((int.tryParse("${baseData?.data?.total}") ?? 0) < (pageNum * 10)) {
|
|
|
|
refreshController.loadNoData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
// return FutureBuilder(
|
|
|
|
// future: queryCommunity(),
|
|
|
|
// builder: (context, position) {
|
|
|
|
return SmartRefresher(
|
|
|
|
controller: refreshController,
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: true,
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
header: MyHeader(),
|
|
|
|
footer: CustomFooter(
|
|
|
|
builder: (context, mode) {
|
|
|
|
return MyFooter(mode);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
onRefresh: _onRefresh,
|
|
|
|
onLoading: () {
|
|
|
|
isLoadMore = true;
|
|
|
|
_onRefresh();
|
|
|
|
},
|
|
|
|
scrollController: scrollController,
|
|
|
|
child: Container(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
child: Container(
|
|
|
|
// color: Color(0xFFF7F7F7),
|
|
|
|
// margin: EdgeInsets.only(top: 16.h),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
CommunityList(
|
|
|
|
comments,
|
|
|
|
userId,
|
|
|
|
0,
|
|
|
|
isList: true,
|
|
|
|
exitFull: () {
|
|
|
|
_onRefresh();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
// },
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
}
|