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.

113 lines
3.2 KiB

3 years ago
import 'package:dio/dio.dart';
3 years ago
import 'package:flutter/material.dart';
3 years ago
import 'package:huixiang/community/community_view/community_dynamic.dart';
3 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/comunity_comment.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
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';
3 years ago
import 'package:shared_preferences/shared_preferences.dart';
3 years ago
class CommunityChildPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CommunityChildPage();
}
}
class _CommunityChildPage extends State<CommunityChildPage> {
3 years ago
RefreshController refreshController = RefreshController();
3 years ago
ApiService apiService;
int pageNum = 1;
List<ComunityComment> comments = [];
3 years ago
3 years ago
@override
3 years ago
void initState() {
super.initState();
3 years ago
_onRefresh();
3 years ago
}
3 years ago
_onRefresh() async {
pageNum = 1;
queryCommunity();
3 years ago
}
3 years ago
queryCommunity() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData<PageInfo<ComunityComment>> baseData = await apiService.trendList({
"onlyFollow": false,
"onlyMe": false,
"pageNum": pageNum,
"pageSize": 10,
"searchKey": ""
}).catchError((error) {
refreshController.refreshFailed();
refreshController.loadFailed();
3 years ago
});
3 years ago
refreshController.refreshCompleted();
refreshController.loadComplete();
if (baseData.isSuccess) {
if (pageNum == 1) {
comments.clear();
}
comments.addAll(baseData.data.list);
print("comments: ${comments.length}");
if (int.tryParse(baseData.data.total) < (pageNum * 10)) {
refreshController.loadNoData();
}
}
3 years ago
}
3 years ago
3 years ago
@override
Widget build(BuildContext context) {
3 years ago
return FutureBuilder(
future: _onRefresh(),
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: queryCommunity,
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return InkWell(
child: CommunityDynamic(comments[position]),
onTap: () {
Navigator.of(context).pushNamed(
'/router/community_details',
arguments: {
"comment": comments[position],
},
);
},
);
},
itemCount: comments.length,
));
},
3 years ago
);
}
}