Showing
3 changed files
with
41 additions
and
1 deletions
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | 4 | ||
| 5 | - Refactor html imports | 5 | - Refactor html imports |
| 6 | - Implement PdfActionBarTheme for actions bar and add method scrollToPage [Aleksei] | 6 | - Implement PdfActionBarTheme for actions bar and add method scrollToPage [Aleksei] |
| 7 | +- Update cursors in zoom mode for web [Aleksei] | ||
| 7 | 8 | ||
| 8 | ## 5.11.1 | 9 | ## 5.11.1 |
| 9 | 10 |
| @@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
| 16 | 16 | ||
| 17 | import 'dart:async'; | 17 | import 'dart:async'; |
| 18 | 18 | ||
| 19 | +import 'package:flutter/foundation.dart'; | ||
| 19 | import 'package:flutter/material.dart'; | 20 | import 'package:flutter/material.dart'; |
| 20 | import 'package:pdf/pdf.dart'; | 21 | import 'package:pdf/pdf.dart'; |
| 21 | 22 | ||
| @@ -51,6 +52,7 @@ class PdfPreviewCustom extends StatefulWidget { | @@ -51,6 +52,7 @@ class PdfPreviewCustom extends StatefulWidget { | ||
| 51 | this.shrinkWrap = false, | 52 | this.shrinkWrap = false, |
| 52 | this.pagesBuilder, | 53 | this.pagesBuilder, |
| 53 | this.enableScrollToPage = false, | 54 | this.enableScrollToPage = false, |
| 55 | + this.onZoomChanged, | ||
| 54 | }) : super(key: key); | 56 | }) : super(key: key); |
| 55 | 57 | ||
| 56 | /// Pdf paper page format | 58 | /// Pdf paper page format |
| @@ -106,6 +108,9 @@ class PdfPreviewCustom extends StatefulWidget { | @@ -106,6 +108,9 @@ class PdfPreviewCustom extends StatefulWidget { | ||
| 106 | /// Whether scroll to page functionality enabled. | 108 | /// Whether scroll to page functionality enabled. |
| 107 | final bool enableScrollToPage; | 109 | final bool enableScrollToPage; |
| 108 | 110 | ||
| 111 | + /// The zoom mode has changed | ||
| 112 | + final ValueChanged<bool>? onZoomChanged; | ||
| 113 | + | ||
| 109 | @override | 114 | @override |
| 110 | PdfPreviewCustomState createState() => PdfPreviewCustomState(); | 115 | PdfPreviewCustomState createState() => PdfPreviewCustomState(); |
| 111 | } | 116 | } |
| @@ -130,6 +135,8 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -130,6 +135,8 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
| 130 | 135 | ||
| 131 | Timer? previewUpdate; | 136 | Timer? previewUpdate; |
| 132 | 137 | ||
| 138 | + MouseCursor _mouseCursor = MouseCursor.defer; | ||
| 139 | + | ||
| 133 | static const _errorMessage = 'Unable to display the document'; | 140 | static const _errorMessage = 'Unable to display the document'; |
| 134 | 141 | ||
| 135 | @override | 142 | @override |
| @@ -137,6 +144,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -137,6 +144,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
| 137 | 144 | ||
| 138 | @override | 145 | @override |
| 139 | void dispose() { | 146 | void dispose() { |
| 147 | + transformationController.dispose(); | ||
| 140 | previewUpdate?.cancel(); | 148 | previewUpdate?.cancel(); |
| 141 | super.dispose(); | 149 | super.dispose(); |
| 142 | } | 150 | } |
| @@ -155,6 +163,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -155,6 +163,7 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
| 155 | preview = null; | 163 | preview = null; |
| 156 | updatePosition = null; | 164 | updatePosition = null; |
| 157 | raster(); | 165 | raster(); |
| 166 | + _zoomChanged(); | ||
| 158 | } | 167 | } |
| 159 | super.didUpdateWidget(oldWidget); | 168 | super.didUpdateWidget(oldWidget); |
| 160 | } | 169 | } |
| @@ -235,7 +244,9 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -235,7 +244,9 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
| 235 | updatePosition = scrollController.position.pixels; | 244 | updatePosition = scrollController.position.pixels; |
| 236 | preview = index; | 245 | preview = index; |
| 237 | transformationController.value.setIdentity(); | 246 | transformationController.value.setIdentity(); |
| 247 | + _updateCursor(SystemMouseCursors.grab); | ||
| 238 | }); | 248 | }); |
| 249 | + _zoomChanged(); | ||
| 239 | }, | 250 | }, |
| 240 | child: PdfPreviewPage( | 251 | child: PdfPreviewPage( |
| 241 | key: key, | 252 | key: key, |
| @@ -271,15 +282,23 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -271,15 +282,23 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
| 271 | } | 282 | } |
| 272 | 283 | ||
| 273 | Widget _zoomPreview() { | 284 | Widget _zoomPreview() { |
| 274 | - return GestureDetector( | 285 | + final zoomPreview = GestureDetector( |
| 275 | onDoubleTap: () { | 286 | onDoubleTap: () { |
| 276 | setState(() { | 287 | setState(() { |
| 277 | preview = null; | 288 | preview = null; |
| 289 | + _updateCursor(MouseCursor.defer); | ||
| 278 | }); | 290 | }); |
| 291 | + _zoomChanged(); | ||
| 279 | }, | 292 | }, |
| 293 | + onLongPressCancel: | ||
| 294 | + kIsWeb ? () => _updateCursor(SystemMouseCursors.grab) : null, | ||
| 295 | + onLongPressDown: | ||
| 296 | + kIsWeb ? (_) => _updateCursor(SystemMouseCursors.grabbing) : null, | ||
| 280 | child: InteractiveViewer( | 297 | child: InteractiveViewer( |
| 281 | transformationController: transformationController, | 298 | transformationController: transformationController, |
| 282 | maxScale: 5, | 299 | maxScale: 5, |
| 300 | + onInteractionEnd: | ||
| 301 | + kIsWeb ? (_) => _updateCursor(SystemMouseCursors.grab) : null, | ||
| 283 | child: Center( | 302 | child: Center( |
| 284 | child: PdfPreviewPage( | 303 | child: PdfPreviewPage( |
| 285 | pageData: pages[preview!], | 304 | pageData: pages[preview!], |
| @@ -289,6 +308,20 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | @@ -289,6 +308,20 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> | ||
| 289 | ), | 308 | ), |
| 290 | ), | 309 | ), |
| 291 | ); | 310 | ); |
| 311 | + return MouseRegion( | ||
| 312 | + cursor: _mouseCursor, | ||
| 313 | + child: zoomPreview, | ||
| 314 | + ); | ||
| 315 | + } | ||
| 316 | + | ||
| 317 | + void _zoomChanged() => widget.onZoomChanged?.call(preview != null); | ||
| 318 | + | ||
| 319 | + void _updateCursor(MouseCursor mouseCursor) { | ||
| 320 | + if (mouseCursor != _mouseCursor) { | ||
| 321 | + setState(() { | ||
| 322 | + _mouseCursor = mouseCursor; | ||
| 323 | + }); | ||
| 324 | + } | ||
| 292 | } | 325 | } |
| 293 | 326 | ||
| 294 | @override | 327 | @override |
| @@ -65,6 +65,7 @@ class PdfPreview extends StatefulWidget { | @@ -65,6 +65,7 @@ class PdfPreview extends StatefulWidget { | ||
| 65 | this.dpi, | 65 | this.dpi, |
| 66 | this.actionBarTheme = const PdfActionBarTheme(), | 66 | this.actionBarTheme = const PdfActionBarTheme(), |
| 67 | this.enableScrollToPage = false, | 67 | this.enableScrollToPage = false, |
| 68 | + this.onZoomChanged, | ||
| 68 | }) : _pagesBuilder = null, | 69 | }) : _pagesBuilder = null, |
| 69 | super(key: key); | 70 | super(key: key); |
| 70 | 71 | ||
| @@ -125,6 +126,7 @@ class PdfPreview extends StatefulWidget { | @@ -125,6 +126,7 @@ class PdfPreview extends StatefulWidget { | ||
| 125 | this.actionBarTheme = const PdfActionBarTheme(), | 126 | this.actionBarTheme = const PdfActionBarTheme(), |
| 126 | required CustomPdfPagesBuilder pagesBuilder, | 127 | required CustomPdfPagesBuilder pagesBuilder, |
| 127 | this.enableScrollToPage = false, | 128 | this.enableScrollToPage = false, |
| 129 | + this.onZoomChanged, | ||
| 128 | }) : _pagesBuilder = pagesBuilder, | 130 | }) : _pagesBuilder = pagesBuilder, |
| 129 | super(key: key); | 131 | super(key: key); |
| 130 | 132 | ||
| @@ -238,6 +240,9 @@ class PdfPreview extends StatefulWidget { | @@ -238,6 +240,9 @@ class PdfPreview extends StatefulWidget { | ||
| 238 | /// Whether scroll to page functionality enabled. | 240 | /// Whether scroll to page functionality enabled. |
| 239 | final bool enableScrollToPage; | 241 | final bool enableScrollToPage; |
| 240 | 242 | ||
| 243 | + /// The zoom mode has changed | ||
| 244 | + final ValueChanged<bool>? onZoomChanged; | ||
| 245 | + | ||
| 241 | @override | 246 | @override |
| 242 | PdfPreviewState createState() => PdfPreviewState(); | 247 | PdfPreviewState createState() => PdfPreviewState(); |
| 243 | } | 248 | } |
| @@ -411,6 +416,7 @@ class PdfPreviewState extends State<PdfPreview> { | @@ -411,6 +416,7 @@ class PdfPreviewState extends State<PdfPreview> { | ||
| 411 | pagesBuilder: widget._pagesBuilder, | 416 | pagesBuilder: widget._pagesBuilder, |
| 412 | dpi: widget.dpi, | 417 | dpi: widget.dpi, |
| 413 | enableScrollToPage: widget.enableScrollToPage, | 418 | enableScrollToPage: widget.enableScrollToPage, |
| 419 | + onZoomChanged: widget.onZoomChanged, | ||
| 414 | ); | 420 | ); |
| 415 | }), | 421 | }), |
| 416 | ), | 422 | ), |
-
Please register or login to post a comment