Showing
1 changed file
with
23 additions
and
32 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,36 +221,41 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -221,36 +221,41 @@ 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 | ||
| 232 | + Widget pageWidget(int index, {Key? key}) => GestureDetector( | ||
| 233 | + onDoubleTap: () { | ||
| 234 | + setState(() { | ||
| 235 | + updatePosition = scrollController.position.pixels; | ||
| 236 | + preview = index; | ||
| 237 | + transformationController.value.setIdentity(); | ||
| 238 | + }); | ||
| 239 | + }, | ||
| 240 | + child: PdfPreviewPage( | ||
| 241 | + key: key, | ||
| 242 | + pageData: pages[index], | ||
| 243 | + pdfPreviewPageDecoration: widget.pdfPreviewPageDecoration, | ||
| 244 | + pageMargin: widget.previewPageMargin, | ||
| 245 | + ), | ||
| 246 | + ); | ||
| 247 | + | ||
| 230 | return widget.enableScrollToPage | 248 | return widget.enableScrollToPage |
| 231 | ? Scrollbar( | 249 | ? Scrollbar( |
| 232 | controller: scrollController, | 250 | controller: scrollController, |
| 233 | child: SingleChildScrollView( | 251 | child: SingleChildScrollView( |
| 234 | controller: scrollController, | 252 | controller: scrollController, |
| 235 | physics: widget.scrollPhysics, | 253 | physics: widget.scrollPhysics, |
| 254 | + padding: widget.padding, | ||
| 236 | child: Column( | 255 | child: Column( |
| 237 | children: List.generate( | 256 | children: List.generate( |
| 238 | pages.length, | 257 | pages.length, |
| 239 | - (index) => GestureDetector( | ||
| 240 | - onDoubleTap: () { | ||
| 241 | - setState(() { | ||
| 242 | - updatePosition = scrollController.position.pixels; | ||
| 243 | - preview = index; | ||
| 244 | - transformationController.value.setIdentity(); | ||
| 245 | - }); | ||
| 246 | - }, | ||
| 247 | - child: PdfPreviewPage( | ||
| 248 | - key: getPageKey(index), | ||
| 249 | - pageData: pages[index], | ||
| 250 | - pdfPreviewPageDecoration: widget.pdfPreviewPageDecoration, | ||
| 251 | - pageMargin: widget.previewPageMargin, | ||
| 252 | - ), | ||
| 253 | - ), | 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