i'm trying to visualize a pdf file inside a container coming from StreamBuilder,
always getting the following error: RenderConstrainedOverflowBox object was given an infinite size during layout.
I have tried wrapping the listView inside an Expanded widget but still getting a different error, tried to fix container height as well but still getting the error.
here is my code:
class MyFile extends StatefulWidget {
const MyFile({super.key});
@override
State<MyFile> createState() => _MyFileState();
}
class _MyFileState extends State<MyFile> {
User? user = FirebaseAuth.instance.currentUser;
PdfViewerController? pdfViewerController;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: 150,
child: SingleChildScrollView(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('cartesP')
.where('userId', isEqualTo: user!.uid)
.limit(1)
.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
QueryDocumentSnapshot x = snapshot.data!.docs[index];
return SfPdfViewer.network(
x['fileUrl'],
controller: pdfViewerController,
);
});
}
return Center(
child: CircularProgressIndicator(),
);
}),
),
),
);
}
}
I have also tried different solutions from threads on stack overflow but none of them worked for me! I'd be grateful for any kind of help!
CodePudding user response:
You don't need to wrap ListView
using SingleChildScrollView
. Because ListView
itself can scroll.
You can try setting height for ListView child.
itemBuilder: (context, index) {
QueryDocumentSnapshot x = snapshot.data!.docs[index];
return Container(
height: 150,
child: SfPdfViewer.network(
x['fileUrl'],
controller: pdfViewerController,
),
);
});