|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:huixiang/community/community_view/community_dynamic.dart';
|
|
|
|
import 'package:huixiang/data/article.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/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/my_footer.dart';
|
|
|
|
import 'package:huixiang/view_widget/no_data_view.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import '../utils/flutter_utils.dart';
|
|
|
|
import '../utils/font_weight.dart';
|
|
|
|
|
|
|
|
class CommunityChildPage extends StatefulWidget {
|
|
|
|
final String typeStr;
|
|
|
|
final Function onScroll;
|
|
|
|
final Function toRelease;
|
|
|
|
|
|
|
|
CommunityChildPage(Key key, this.typeStr, this.onScroll, this.toRelease)
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return CommunityChildPageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CommunityChildPageState extends State<CommunityChildPage>
|
|
|
|
with AutomaticKeepAliveClientMixin {
|
|
|
|
RefreshController refreshController = RefreshController();
|
|
|
|
ApiService? apiService;
|
|
|
|
int pageNum = 1;
|
|
|
|
String? userId;
|
|
|
|
bool isLoadMore = false;
|
|
|
|
bool isRefresh = true;
|
|
|
|
bool isLoadingData = false;
|
|
|
|
ScrollController sc = ScrollController();
|
|
|
|
List<Article> articles = [];
|
|
|
|
int _currentIndex = 0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
sc.addListener(() {
|
|
|
|
widget.onScroll();
|
|
|
|
if (sc.offset >= 500) {
|
|
|
|
_currentIndex =1;
|
|
|
|
}else if(sc.offset <= 500){
|
|
|
|
_currentIndex = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
onRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
onRefresh() async {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
///动态列表
|
|
|
|
queryCommunity(String? searchKey) async {
|
|
|
|
if (!isRefresh) {
|
|
|
|
isRefresh = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isLoadingData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isLoadingData = true;
|
|
|
|
if (apiService == null) {
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance();
|
|
|
|
userId = value.getString('userId');
|
|
|
|
apiService = ApiService(Dio(),
|
|
|
|
context: context,
|
|
|
|
token: value.getString("token"),
|
|
|
|
showLoading: false);
|
|
|
|
}
|
|
|
|
if (isLoadMore) {
|
|
|
|
pageNum += 1;
|
|
|
|
isLoadMore = false;
|
|
|
|
} else if (searchKey == null) pageNum = 1;
|
|
|
|
BaseData<PageInfo<ComunityComment>>? baseData = await apiService?.trendList({
|
|
|
|
"mid": "",
|
|
|
|
"onlyFollow": widget.typeStr == "关注" ? true : false,
|
|
|
|
"onlyMe": false,
|
|
|
|
"pageNum": searchKey == null ? pageNum : 1,
|
|
|
|
"pageSize": 10,
|
|
|
|
"searchKey": searchKey ?? ""
|
|
|
|
}).catchError((error) {
|
|
|
|
SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type),
|
|
|
|
alignment: Alignment.center);
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
if (baseData?.data?.list?.isNotEmpty ?? false)
|
|
|
|
articles.forEach((element) {
|
|
|
|
if (element.id == searchKey) {
|
|
|
|
element.content = jsonEncode(baseData?.data?.list?[0].subjectInfo);
|
|
|
|
element.mainTitle = baseData?.data?.list?[0].subject;
|
|
|
|
element.followed = baseData?.data?.list?[0].selfFollow;
|
|
|
|
element.liked = baseData?.data?.list?[0].selfLike;
|
|
|
|
element.authorHeadImg = baseData?.data?.list?[0].memberInfo?.avatar;
|
|
|
|
element.authorName = baseData?.data?.list?[0].memberInfo?.nickname;
|
|
|
|
element.location = baseData?.data?.list?[0].location;
|
|
|
|
element.createTime = baseData?.data?.list?[0].createTime;
|
|
|
|
element.author = baseData?.data?.list?[0].memberInfo?.mid;
|
|
|
|
element.viewers = baseData?.data?.list?[0].viewers;
|
|
|
|
element.likes = baseData?.data?.list?[0].likes;
|
|
|
|
element.comments = baseData?.data?.list?[0].comments;
|
|
|
|
this.isRefresh = false;
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isLoadingData = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
super.build(context);
|
|
|
|
return FutureBuilder(
|
|
|
|
future: queryCommunity(null),
|
|
|
|
builder: (context, position) {
|
|
|
|
return Stack(
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
children: [
|
|
|
|
SmartRefresher(
|
|
|
|
controller: refreshController,
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: (articles.length == 0) ? false:true,
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
header: MyHeader(),
|
|
|
|
footer: CustomFooter(
|
|
|
|
builder: (context, mode) {
|
|
|
|
return MyFooter(mode);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
onRefresh: onRefresh,
|
|
|
|
onLoading: () {
|
|
|
|
isLoadMore = true;
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: (articles.length == 0)
|
|
|
|
? NoDataView(
|
|
|
|
src: "assets/image/guan_zhu.webp",
|
|
|
|
isShowBtn: false,
|
|
|
|
text: "目前暂无添加关注,可在推荐中关注自己喜欢的人哦~",
|
|
|
|
fontSize: 16.sp,
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
top: 120.h, left: 60.w, right: 60.w,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: ListView.builder(
|
|
|
|
controller: sc,
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return InkWell(
|
|
|
|
child: CommunityDynamic(
|
|
|
|
articles[position],
|
|
|
|
0,
|
|
|
|
userId: userId,
|
|
|
|
isList: true,
|
|
|
|
exitFull: () {
|
|
|
|
// setState(() {
|
|
|
|
// onRefresh();
|
|
|
|
// });
|
|
|
|
|
|
|
|
queryCommunity(articles[position].id);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
'/router/community_details',
|
|
|
|
arguments: {
|
|
|
|
"businessId": articles[position].id,
|
|
|
|
"userId": userId,
|
|
|
|
},
|
|
|
|
).then((value) {
|
|
|
|
// onRefresh();
|
|
|
|
// setState(() {});
|
|
|
|
queryCommunity(articles[position].id);
|
|
|
|
});
|
|
|
|
// setState(() {});
|
|
|
|
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: articles.length,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
widget.toRelease();
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.only(bottom: 31, right: 14),
|
|
|
|
child: Image.asset(
|
|
|
|
"assets/image/fa_bu.webp",
|
|
|
|
width: 55,
|
|
|
|
height: 55,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if(_currentIndex == 1)
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
sc.jumpTo(0);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.only(bottom:120.h, right: 14.w),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(100),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
height:48,
|
|
|
|
width: 48,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Icon(Icons.arrow_upward,size: 16,color: Color(0xFF808080),),
|
|
|
|
Text(
|
|
|
|
"顶部",
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Color(0xFF808080),
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
|
|
|
}
|