|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:huixiang/community/community_list.dart';
|
|
|
|
import 'package:huixiang/community/community_view/community_dynamic.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/article.dart';
|
|
|
|
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';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/my_appbar.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 ReleasePage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _ReleasePage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ReleasePage extends State<ReleasePage> {
|
|
|
|
RefreshController refreshController = RefreshController();
|
|
|
|
final ScrollController scrollController = ScrollController();
|
|
|
|
ApiService apiService;
|
|
|
|
int pageNum = 0;
|
|
|
|
String userId;
|
|
|
|
bool isLoadMore = false;
|
|
|
|
|
|
|
|
List<ComunityComment> comments = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_onRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
_onRefresh() async {
|
|
|
|
queryCommunity();
|
|
|
|
}
|
|
|
|
|
|
|
|
///动态列表
|
|
|
|
queryCommunity() async {
|
|
|
|
if (apiService == null) {
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance();
|
|
|
|
userId = value.getString('userId');
|
|
|
|
apiService = ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: value.getString("token"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if(isLoadMore){
|
|
|
|
pageNum += 1;
|
|
|
|
isLoadMore = false;
|
|
|
|
}else pageNum = 1;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder(
|
|
|
|
future: queryCommunity(),
|
|
|
|
builder: (context, position) {
|
|
|
|
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: () {
|
|
|
|
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,
|
|
|
|
1,
|
|
|
|
isList: true,
|
|
|
|
exitFull: () {
|
|
|
|
_onRefresh();
|
|
|
|
},
|
|
|
|
removalDynamic: () {
|
|
|
|
_onRefresh();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|