我从互联网上拉数据,但我只能在屏幕上显示1条数据,我得到了大小问题,我如何解决这两个错误?
@override
Widget build(BuildContext context) {
return FutureBuilder<List<PostModel>?>(
future: _postService.fetchPostsItems(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final result = snapshot.data!;
return ListView.builder(
shrinkWrap: true,
itemCount: result.length,
itemBuilder: ((context, index) {
return CustomComponents(
title: result[index].authorName ?? '',
subTitle: result[index].createdAt ?? '',
profileImageUrl: result[index].authorProfileImage ?? '',
postImageUrl: result[index].media ?? '',
description: result[index].description ?? '',
likeCount: result[index].likeCount ?? 0,
dislikeCount: result[index].disLikeCount ?? 0,
commentCount: result[index].comments?.length ?? 0,
commentTitle: result[index].comments?[index].authorName ?? '',
commentDescription: result[index].description ?? '',
commentImageUrl: result[index].authorProfileImage ?? '',
);
}),
);
}
return const Center(child: CircularProgressIndicator());
},
);
}
1条答案
按热度按时间rt4zxlrg1#
这可能会导致问题。您的ListView与result一样长,但这并不意味着result中的注解与结果长度一样长。