showing this error when I use column in StreamBuilder
error:
════════ Exception caught by rendering library ═════════════════════════════════ RenderBox was not laid out: RenderRepaintBoundary#6d45d relayoutBoundary=up2 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': package:flutter/…/rendering/box.dart:1 Failed assertion: line 2001 pos 12: 'hasSize'
The relevant error-causing widget was Column
body: StreamBuilder(
stream: FirebaseFirestore.instance
.collection("posts")
.orderBy('datePublished', descending: true)
.snapshots(),
builder: (context,
AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>> snapshot) {
//connection no problem
return Column(
children: [
SizedBox(
height: 100.0,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: 5,
itemBuilder: (context, index) => Container(
padding: const EdgeInsets.all(12),
margin: const EdgeInsets.all(12),
height: 250,
width: 150,
color: Colors.pink,
),
),
),
ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) => PostCard(
snap: snapshot.data!.docs[index].data(),
),
)
],
);
},
));
CodePudding user response:
ListView
need bounded size, when you wrap it with Expanded
you set its bound, try this:
Expanded(
child: ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) => PostCard(
snap: snapshot.data!.docs[index].data(),
),
),
),