The problem is, that in every pdf renderer library, if I put the pdf view in SingleChildScrollView widget, I always get this error: FlutterError (RenderConstrainedOverflowBox object was given an infinite size during layout.
I want to achieve the left version!!!
This is how I solved now, but I think that this solution is not very clean…. Can someone give me a nice solution?
class _PdfPageState extends State<PdfPage> {
bool pdfDownloaded = false;
late double pdfHeight;
@override
void initState() {
super.initState();
loadPdf();
}
void loadPdf() async {
PdfDocument doc = await PdfDocument.openAsset('assets/hello.pdf');
if (mounted) {
double width = MediaQuery.sizeOf(context).width;
setState(() {
pdfDownloaded = true;
pdfHeight = doc.pageCount * width * 1.28;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
const Text("Before pdf"),
pdfDownloaded
? const CircularProgressIndicator()
: SizedBox(height: pdfHeight, child: PdfViewer.openAsset('assets/hello.pdf')),
const Text("After pdf"),
],
),
);
}
}
1