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.

135 lines
4.0 KiB

3 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
3 years ago
import 'package:huixiang/community/community_view/community_dynamic.dart';
3 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
3 years ago
import 'package:huixiang/retrofit/data/comunity_comment.dart';
import 'package:huixiang/retrofit/data/page.dart';
3 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/view_widget/classic_header.dart';
3 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
3 years ago
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 ReleasePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ReleasePage();
}
}
class _ReleasePage extends State<ReleasePage> {
3 years ago
RefreshController refreshController = RefreshController();
3 years ago
ApiService apiService;
3 years ago
int pageNum = 0;
3 years ago
List<ComunityComment> comments = [];
3 years ago
@override
void initState() {
super.initState();
3 years ago
_onRefresh();
}
3 years ago
3 years ago
_onRefresh() async {
3 years ago
pageNum = 0;
3 years ago
setState(() {});
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"),
);
}
3 years ago
pageNum += 1;
3 years ago
BaseData<PageInfo<ComunityComment>> baseData = await apiService.trendList({
"onlyFollow": false,
"onlyMe": true,
"pageNum": pageNum,
"pageSize": 10,
"searchKey": ""
}).catchError((error) {
refreshController.refreshFailed();
refreshController.loadFailed();
});
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
@override
Widget build(BuildContext context) {
3 years ago
return FutureBuilder(
future: queryCommunity(),
builder: (context, position) {
3 years ago
return Scaffold(
appBar: MyAppBar(
background: Color(0xFFFFFFFF),
leadingColor: Colors.black,
title: "动态",
titleColor: Colors.black,
titleSize: 18.sp,
),
body: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: true,
physics: BouncingScrollPhysics(),
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: _onRefresh,
onLoading: () {
setState(() {});
3 years ago
},
3 years ago
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return InkWell(
child: CommunityDynamic(
comments[position],
3 years ago
1,exitFull: (){setState(() {
3 years ago
_onRefresh();
3 years ago
});},
3 years ago
removalDynamic: () {
_onRefresh();
3 years ago
},
3 years ago
),
onTap: () {
Navigator.of(context).pushNamed(
'/router/community_details',
arguments: {
"comment": comments[position],
},
);
},
);
},
itemCount: comments.length,
)),
);
3 years ago
},
3 years ago
);
}
}