[英]Flutter: Stream Builder -> List View 99,285 unexpected pixels
I am trying to pull user data from Firebase using a List View Builder inside of a stream builder.我正在尝试使用 stream 构建器内部的列表视图构建器从 Firebase 中提取用户数据。 I'm getting 99,285 unexpected pixels at the bottom of the screen.屏幕底部出现 99,285 个意外像素。 The database is not very big at all, there are 2 users with 5 fields each but I'm only asking for one users data in this Stream.数据库根本不是很大,有 2 个用户,每个用户有 5 个字段,但我只要求这个 Stream 中的一个用户数据。 This makes me think there's some kind of repeating loop, there shouldn't be this much extra space but I don't know where I'm going wrong.这让我觉得有某种重复循环,不应该有这么多额外的空间,但我不知道我哪里出错了。 I'm more curious as to what the pixels are, I could put a size constraint on the list view but I still don't want to be pulling unnecessary data every time I load the user page.我对像素是什么更好奇,我可以在列表视图上设置大小限制,但我仍然不想每次加载用户页面时都拉取不必要的数据。
Error错误
Error: Cannot hit test a render box with no size.
The hitTest() method was called on this RenderBox: (...)
StreamBuilder<QuerySnapshot<Object?>> ← Row ← Column ← Center ← ⋯
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(unconstrained)
layer: OffsetLayer#6ffdf DETACHED
size: MISSING
Stream Builder -> List View Stream 生成器 -> 列表视图
StreamBuilder(
stream: collectionReference
.where("uid", isEqualTo: user.uid)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return const Text('Something went wrong.');
}
final data = snapshot.requireData;
return ListView.builder(
shrinkWrap: true, // I thought this line was supposed to stop the overflow
itemCount: data.size,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(top: 8.0, left: 8.0), // A: This sets the padding for the profile picture
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
height: 80.0,
width: 80.0,
child: FittedBox(
//fit: BoxFit.contain,
child: GestureDetector(
onTap: () => uploadToStorage(),
child: CircleAvatar(
// radius: 20,
backgroundImage: NetworkImage(data.docs[index]['profileImageUrl']),
),
),
),
),
),
);
},
);
},
),
I wrapped the Stream Builder in a ConstrainedBox widget to solve the issue.我将 Stream Builder 包装在 ConstrainedBox 小部件中以解决该问题。 I also solved the error: "snapshot has no data or error by implementing a few if statements to check for snapshot data.我还解决了错误:“通过执行一些 if 语句来检查快照数据,快照没有数据或错误。
ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 70,
minHeight: 70,
maxWidth: 150,
maxHeight: 150,
),
child: StreamBuilder(
stream: collectionReference
.where("uid", isEqualTo: user.uid)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return const Text('Loading...');
}
if (snapshot.hasError) {
return const Text('Something went wrong.');
}
final data = snapshot.requireData;
// listview height needs to be set
return ListView.builder(
shrinkWrap: true, // I thought this line was supposed to stop the overflow
itemCount: data.size,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(
top: 8.0,
left: 8.0
), // A: This sets the padding for the profile picture
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
height: 80.0,
width: 80.0,
child: FittedBox(
fit: BoxFit.contain,
child: GestureDetector(
onTap: () => uploadToStorage(),
child: CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
data.docs[index]['profileImageUrl']),
),
),
),
),
),
);
},
);
},
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.