packages.flutter
packages.flutter copied to clipboard
[native_pdf_view] controller.page results in Null check operator used on a null value
Describe the bug
The page
getter in PdfController
results in
Null check operator used on a null value
because _pdfViewState
is null. There appears to be no way for the client code to check if _pdfViewState
is null before trying to access it either.
To Reproduce
Column(
children: [
Expanded(
child: PdfView(
controller: pdfController,
),
),
Row(
children: [
Text('${pdfController.page}/${pdfController.pagesCount}'),
]
)
],
)
Expected behavior
I would expect either that the page
getter would check if _pdfViewState
is null, or some way for me to check it from the client code (for example something like if( pdfController.ready) ...
).
The example code works around the issue by storing the current and total page numbers in local variables, but this shouldn't be necessary. If this is the recommended way to do things, then why does PdfController
even expose the page
and pagesCount
getters in the first place?
I'm not an expert in null safety by any means, but It seems like an anti pattern to use the !
operator on a nullable variable if it's not absolutely guaranteed to be non-null at that point?