Showing
1 changed file
with
20 additions
and
29 deletions
@@ -114,7 +114,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -114,7 +114,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
114 | with PdfPreviewRaster { | 114 | with PdfPreviewRaster { |
115 | final listView = GlobalKey(); | 115 | final listView = GlobalKey(); |
116 | 116 | ||
117 | - late List<GlobalKey> _pageGlobalKeys; | 117 | + List<GlobalKey> _pageGlobalKeys = <GlobalKey>[]; |
118 | 118 | ||
119 | bool infoLoaded = false; | 119 | bool infoLoaded = false; |
120 | 120 | ||
@@ -221,22 +221,15 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -221,22 +221,15 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
221 | ); | 221 | ); |
222 | } | 222 | } |
223 | 223 | ||
224 | - _pageGlobalKeys = List.generate(pages.length, (index) => GlobalKey()); | 224 | + if (widget.enableScrollToPage) { |
225 | + _pageGlobalKeys = List.generate(pages.length, (_) => GlobalKey()); | ||
226 | + } | ||
225 | 227 | ||
226 | if (widget.pagesBuilder != null) { | 228 | if (widget.pagesBuilder != null) { |
227 | return widget.pagesBuilder!(context, pages); | 229 | return widget.pagesBuilder!(context, pages); |
228 | } | 230 | } |
229 | 231 | ||
230 | - return widget.enableScrollToPage | ||
231 | - ? Scrollbar( | ||
232 | - controller: scrollController, | ||
233 | - child: SingleChildScrollView( | ||
234 | - controller: scrollController, | ||
235 | - physics: widget.scrollPhysics, | ||
236 | - child: Column( | ||
237 | - children: List.generate( | ||
238 | - pages.length, | ||
239 | - (index) => GestureDetector( | 232 | + Widget pageWidget(int index, {Key? key}) => GestureDetector( |
240 | onDoubleTap: () { | 233 | onDoubleTap: () { |
241 | setState(() { | 234 | setState(() { |
242 | updatePosition = scrollController.position.pixels; | 235 | updatePosition = scrollController.position.pixels; |
@@ -245,12 +238,24 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -245,12 +238,24 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
245 | }); | 238 | }); |
246 | }, | 239 | }, |
247 | child: PdfPreviewPage( | 240 | child: PdfPreviewPage( |
248 | - key: getPageKey(index), | 241 | + key: key, |
249 | pageData: pages[index], | 242 | pageData: pages[index], |
250 | pdfPreviewPageDecoration: widget.pdfPreviewPageDecoration, | 243 | pdfPreviewPageDecoration: widget.pdfPreviewPageDecoration, |
251 | pageMargin: widget.previewPageMargin, | 244 | pageMargin: widget.previewPageMargin, |
252 | ), | 245 | ), |
253 | - ), | 246 | + ); |
247 | + | ||
248 | + return widget.enableScrollToPage | ||
249 | + ? Scrollbar( | ||
250 | + controller: scrollController, | ||
251 | + child: SingleChildScrollView( | ||
252 | + controller: scrollController, | ||
253 | + physics: widget.scrollPhysics, | ||
254 | + padding: widget.padding, | ||
255 | + child: Column( | ||
256 | + children: List.generate( | ||
257 | + pages.length, | ||
258 | + (index) => pageWidget(index, key: getPageKey(index)), | ||
254 | ), | 259 | ), |
255 | ), | 260 | ), |
256 | ), | 261 | ), |
@@ -261,21 +266,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -261,21 +266,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
261 | physics: widget.scrollPhysics, | 266 | physics: widget.scrollPhysics, |
262 | padding: widget.padding, | 267 | padding: widget.padding, |
263 | itemCount: pages.length, | 268 | itemCount: pages.length, |
264 | - itemBuilder: (BuildContext context, int index) => GestureDetector( | ||
265 | - onDoubleTap: () { | ||
266 | - setState(() { | ||
267 | - updatePosition = scrollController.position.pixels; | ||
268 | - preview = index; | ||
269 | - transformationController.value.setIdentity(); | ||
270 | - }); | ||
271 | - }, | ||
272 | - child: PdfPreviewPage( | ||
273 | - key: getPageKey(index), | ||
274 | - pageData: pages[index], | ||
275 | - pdfPreviewPageDecoration: widget.pdfPreviewPageDecoration, | ||
276 | - pageMargin: widget.previewPageMargin, | ||
277 | - ), | ||
278 | - ), | 269 | + itemBuilder: (BuildContext context, int index) => pageWidget(index), |
279 | ); | 270 | ); |
280 | } | 271 | } |
281 | 272 |
-
Please register or login to post a comment