Committed by
David PHAM-VAN
Init pages keys after `pages` is populated
Showing
1 changed file
with
7 additions
and
10 deletions
@@ -110,7 +110,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -110,7 +110,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
110 | with PdfPreviewRaster { | 110 | with PdfPreviewRaster { |
111 | final listView = GlobalKey(); | 111 | final listView = GlobalKey(); |
112 | 112 | ||
113 | - late List<GlobalKey> _pageGlobalKeys; | 113 | + late final List<GlobalKey> _pageGlobalKeys; |
114 | 114 | ||
115 | bool infoLoaded = false; | 115 | bool infoLoaded = false; |
116 | 116 | ||
@@ -174,15 +174,6 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -174,15 +174,6 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
174 | super.didChangeDependencies(); | 174 | super.didChangeDependencies(); |
175 | } | 175 | } |
176 | 176 | ||
177 | - @override | ||
178 | - void initState() { | ||
179 | - super.initState(); | ||
180 | - _pageGlobalKeys = List.generate( | ||
181 | - pages.length, | ||
182 | - (index) => GlobalKey(debugLabel: 'pdf-page-$index'), | ||
183 | - ); | ||
184 | - } | ||
185 | - | ||
186 | void scrollToPage( | 177 | void scrollToPage( |
187 | int index, { | 178 | int index, { |
188 | Duration duration = Duration.zero, | 179 | Duration duration = Duration.zero, |
@@ -221,9 +212,15 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -221,9 +212,15 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
221 | ); | 212 | ); |
222 | } | 213 | } |
223 | 214 | ||
215 | + _pageGlobalKeys = List.generate( | ||
216 | + pages.length, | ||
217 | + (index) => GlobalKey(debugLabel: 'pdf-page-$index'), | ||
218 | + ); | ||
219 | + | ||
224 | if (widget.pagesBuilder != null) { | 220 | if (widget.pagesBuilder != null) { |
225 | return widget.pagesBuilder!(context, pages); | 221 | return widget.pagesBuilder!(context, pages); |
226 | } | 222 | } |
223 | + | ||
227 | return ListView.builder( | 224 | return ListView.builder( |
228 | controller: scrollController, | 225 | controller: scrollController, |
229 | shrinkWrap: widget.shrinkWrap, | 226 | shrinkWrap: widget.shrinkWrap, |
-
Please register or login to post a comment