Browse Source

布局更改;

zyh
w-R 3 years ago
parent
commit
b901995bd3
  1. 225
      lib/community/community_child_page.dart

225
lib/community/community_child_page.dart

@ -20,7 +20,8 @@ class CommunityChildPage extends StatefulWidget {
final Function onScroll; final Function onScroll;
final Function toRelease; final Function toRelease;
CommunityChildPage(Key key, this.typeStr,this.onScroll,this.toRelease): super(key: key); CommunityChildPage(Key key, this.typeStr, this.onScroll, this.toRelease)
: super(key: key);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -28,7 +29,8 @@ class CommunityChildPage extends StatefulWidget {
} }
} }
class CommunityChildPageState extends State<CommunityChildPage> with AutomaticKeepAliveClientMixin { class CommunityChildPageState extends State<CommunityChildPage>
with AutomaticKeepAliveClientMixin {
RefreshController refreshController = RefreshController(); RefreshController refreshController = RefreshController();
ApiService apiService; ApiService apiService;
int pageNum = 1; int pageNum = 1;
@ -54,68 +56,64 @@ class CommunityChildPageState extends State<CommunityChildPage> with AutomaticKe
/// ///
queryCommunity(String searchKey) async { queryCommunity(String searchKey) async {
if(!isRefresh){ if (!isRefresh) {
isRefresh = true; isRefresh = true;
return; return;
} }
if(isLoadingData){ if (isLoadingData) {
return; return;
} }
isLoadingData = true; isLoadingData = true;
if (apiService == null) { if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance(); SharedPreferences value = await SharedPreferences.getInstance();
userId = value.getString('userId'); userId = value.getString('userId');
apiService = ApiService( apiService = ApiService(Dio(),
Dio(), context: context,
context: context, token: value.getString("token"),
token: value.getString("token"), showLoading: false);
showLoading: false
);
} }
if(isLoadMore){ if (isLoadMore) {
pageNum += 1; pageNum += 1;
isLoadMore = false; isLoadMore = false;
} } else if (searchKey == null) pageNum = 1;
else if(searchKey == null)pageNum = 1;
BaseData<PageInfo<ComunityComment>> baseData = await apiService.trendList({ BaseData<PageInfo<ComunityComment>> baseData = await apiService.trendList({
"mid":"", "mid": "",
"onlyFollow": widget.typeStr == "关注" ? true : false, "onlyFollow": widget.typeStr == "关注" ? true : false,
"onlyMe": false, "onlyMe": false,
"pageNum": searchKey == null?pageNum:1, "pageNum": searchKey == null ? pageNum : 1,
"pageSize": 10, "pageSize": 10,
"searchKey": searchKey??"" "searchKey": searchKey ?? ""
}).catchError((error) { }).catchError((error) {
if(searchKey == null) { if (searchKey == null) {
refreshController.refreshFailed(); refreshController.refreshFailed();
refreshController.loadFailed(); refreshController.loadFailed();
} }
}); });
if(searchKey == null) { if (searchKey == null) {
refreshController.refreshCompleted(); refreshController.refreshCompleted();
refreshController.loadComplete(); refreshController.loadComplete();
} }
if (baseData.isSuccess) { if (baseData.isSuccess) {
if(searchKey != null){ if (searchKey != null) {
if(baseData?.data?.list != null && baseData.data.list.isNotEmpty) if (baseData?.data?.list != null && baseData.data.list.isNotEmpty)
articles.forEach((element) { articles.forEach((element) {
if(element.id == searchKey){ if (element.id == searchKey) {
element.content = jsonEncode(baseData.data.list[0].subjectInfo); element.content = jsonEncode(baseData.data.list[0].subjectInfo);
element.mainTitle =baseData.data.list[0].subject; element.mainTitle = baseData.data.list[0].subject;
element.followed = baseData.data.list[0].selfFollow; element.followed = baseData.data.list[0].selfFollow;
element.authorHeadImg = baseData.data.list[0].memberInfo?.avatar; element.authorHeadImg = baseData.data.list[0].memberInfo?.avatar;
element.authorName = baseData.data.list[0].memberInfo?.nickname; element.authorName = baseData.data.list[0].memberInfo?.nickname;
element.location = baseData.data.list[0].location; element.location = baseData.data.list[0].location;
element.createTime = baseData.data.list[0].createTime; element.createTime = baseData.data.list[0].createTime;
element.author = baseData.data.list[0].memberInfo?.mid; element.author = baseData.data.list[0].memberInfo?.mid;
element.viewers = baseData.data.list[0]?.viewers; element.viewers = baseData.data.list[0]?.viewers;
element.likes = baseData.data.list[0]?.likes; element.likes = baseData.data.list[0]?.likes;
element.comments = baseData.data.list[0]?.comments; element.comments = baseData.data.list[0]?.comments;
this.isRefresh = false; this.isRefresh = false;
setState(() { setState(() {});
}); }
} });
}); } else {
}else{
if (pageNum == 1) { if (pageNum == 1) {
articles.clear(); articles.clear();
} }
@ -123,7 +121,7 @@ class CommunityChildPageState extends State<CommunityChildPage> with AutomaticKe
var article = Article(); var article = Article();
article.id = element.id; article.id = element.id;
article.content = jsonEncode(element.subjectInfo); article.content = jsonEncode(element.subjectInfo);
article.mainTitle =element.subject; article.mainTitle = element.subject;
article.followed = element.selfFollow; article.followed = element.selfFollow;
article.authorHeadImg = element.memberInfo?.avatar; article.authorHeadImg = element.memberInfo?.avatar;
article.authorName = element.memberInfo?.nickname; article.authorName = element.memberInfo?.nickname;
@ -152,81 +150,82 @@ class CommunityChildPageState extends State<CommunityChildPage> with AutomaticKe
return FutureBuilder( return FutureBuilder(
future: queryCommunity(null), future: queryCommunity(null),
builder: (context, position) { builder: (context, position) {
return SmartRefresher( return Stack(
controller: refreshController, alignment: Alignment.bottomRight,
enablePullDown: true, children: [
enablePullUp: true, SmartRefresher(
physics: BouncingScrollPhysics(), controller: refreshController,
header: MyHeader(), enablePullDown: true,
footer: CustomFooter( enablePullUp: true,
builder: (context, mode) { physics: BouncingScrollPhysics(),
return MyFooter(mode); header: MyHeader(),
}, footer: CustomFooter(
), builder: (context, mode) {
onRefresh: onRefresh, return MyFooter(mode);
onLoading: () {
isLoadMore = true;
setState(() {});
},
child: Stack(
alignment: Alignment.bottomRight,
children: [
(articles == null || 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();
});
},
),
onTap: () {
Navigator.of(context).pushNamed(
'/router/community_details',
arguments: {
"businessId": articles[position].id,
"userId": userId,
},
).then((value) {
onRefresh();
setState(() {});
});
setState(() {});
},
);
}, },
itemCount: articles.length,
), ),
GestureDetector( onRefresh: onRefresh,
onTap: (){ onLoading: () {
widget.toRelease(); isLoadMore = true;
}, setState(() {});
child: Container( },
margin: EdgeInsets.only(bottom:31,right: 14), child: (articles == null || articles.length == 0)
child: Image.asset( ? NoDataView(
"assets/image/fa_bu.webp", src: "assets/image/guan_zhu.webp",
width: 55, isShowBtn: false,
height: 55, 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();
});
},
),
onTap: () {
Navigator.of(context).pushNamed(
'/router/community_details',
arguments: {
"businessId": articles[position].id,
"userId": userId,
},
).then((value) {
onRefresh();
setState(() {});
});
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,
), ),
) ),
], )
), ],
); );
}, },
); );

Loading…
Cancel
Save