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.

241 lines
8.0 KiB

import 'dart:convert';
3 years ago
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
3 years ago
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';
3 years ago
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';
3 years ago
import 'package:huixiang/view_widget/no_data_view.dart';
3 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
3 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import '../utils/flutter_utils.dart';
import '../utils/font_weight.dart';
3 years ago
class CommunityChildPage extends StatefulWidget {
3 years ago
final String typeStr;
final Function onScroll;
3 years ago
final Function toRelease;
3 years ago
3 years ago
CommunityChildPage(Key key, this.typeStr, this.onScroll, this.toRelease)
: super(key: key);
3 years ago
3 years ago
@override
State<StatefulWidget> createState() {
return CommunityChildPageState();
3 years ago
}
}
3 years ago
class CommunityChildPageState extends State<CommunityChildPage>
with AutomaticKeepAliveClientMixin {
3 years ago
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;
3 years ago
3 years ago
@override
3 years ago
void initState() {
super.initState();
sc.addListener(() {
widget.onScroll();
if (sc.offset >= 500) {
_currentIndex =1;
}else if(sc.offset <= 500){
_currentIndex = 0;
}
});
onRefresh();
3 years ago
}
onRefresh() async {
3 years ago
setState(() {});
3 years ago
}
3 years ago
///动态列表
queryCommunity(String? searchKey) async {
3 years ago
if (!isRefresh) {
isRefresh = true;
return;
}
3 years ago
if (isLoadingData) {
return;
}
3 years ago
isLoadingData = true;
if (isLoadMore) {
pageNum += 1;
isLoadMore = false;
3 years ago
} else if (searchKey == null) pageNum = 1;
BaseData<PageInfo<ComunityComment>>? baseData = await apiService?.trendList({
3 years ago
"mid": "",
3 years ago
"onlyFollow": widget.typeStr == "关注" ? true : false,
3 years ago
"onlyMe": false,
3 years ago
"pageNum": searchKey == null ? pageNum : 1,
3 years ago
"pageSize": 10,
3 years ago
"searchKey": searchKey ?? ""
3 years ago
}).catchError((error) {
SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type),
alignment: Alignment.center);
3 years ago
});
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(() {});
}
3 years ago
});
}
isLoadingData = false;
3 years ago
}
3 years ago
3 years ago
@override
Widget build(BuildContext context) {
3 years ago
super.build(context);
3 years ago
return FutureBuilder(
3 years ago
future: queryCommunity(null),
3 years ago
builder: (context, position) {
3 years ago
return Stack(
alignment: Alignment.bottomRight,
children: [
SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: (articles.length == 0) ? false:true,
3 years ago
physics: BouncingScrollPhysics(),
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
3 years ago
},
3 years ago
),
3 years ago
onRefresh: onRefresh,
onLoading: () {
isLoadMore = true;
setState(() {});
},
child: (articles.length == 0)
3 years ago
? 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,
),
3 years ago
)
: 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);
3 years ago
},
),
onTap: () {
Navigator.of(context).pushNamed(
'/router/community_details',
arguments: {
"businessId": articles[position].id,
"userId": userId,
},
).then((value) {
// onRefresh();
// setState(() {});
queryCommunity(articles[position].id);
3 years ago
});
// setState(() {});
3 years ago
},
);
},
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,
3 years ago
),
3 years ago
),
),
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,
),
),
],
),
),
),
3 years ago
],
3 years ago
);
3 years ago
},
3 years ago
);
}
3 years ago
@override
bool get wantKeepAlive => true;
3 years ago
}