Showing
2 changed files
with
20 additions
and
9 deletions
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | ## 5.2.0 | 3 | ## 5.2.0 |
4 | 4 | ||
5 | - Improve Android page format detection [Deepak] | 5 | - Improve Android page format detection [Deepak] |
6 | +- Add previewPageMargin and padding parameters [Deepak] | ||
7 | +- Fix Scrollbar positionning and default margins | ||
6 | 8 | ||
7 | ## 5.1.0 | 9 | ## 5.1.0 |
8 | 10 |
@@ -115,7 +115,7 @@ class PdfPreview extends StatefulWidget { | @@ -115,7 +115,7 @@ class PdfPreview extends StatefulWidget { | ||
115 | 115 | ||
116 | /// margin for the document preview page | 116 | /// margin for the document preview page |
117 | /// | 117 | /// |
118 | - /// defaults to [EdgeInsets.only(left: 8, top: 8, right: 8, bottom: 12,)], | 118 | + /// defaults to [EdgeInsets.only(left: 20, top: 8, right: 20, bottom: 12)], |
119 | final EdgeInsets? previewPageMargin; | 119 | final EdgeInsets? previewPageMargin; |
120 | 120 | ||
121 | /// padding for the pdf_preview widget | 121 | /// padding for the pdf_preview widget |
@@ -146,7 +146,9 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -146,7 +146,9 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
146 | 146 | ||
147 | double? updatePosition; | 147 | double? updatePosition; |
148 | 148 | ||
149 | - final scrollController = ScrollController(); | 149 | + final scrollController = ScrollController( |
150 | + keepScrollOffset: true, | ||
151 | + ); | ||
150 | 152 | ||
151 | final transformationController = TransformationController(); | 153 | final transformationController = TransformationController(); |
152 | 154 | ||
@@ -355,8 +357,7 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -355,8 +357,7 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
355 | return const Center(child: CircularProgressIndicator()); | 357 | return const Center(child: CircularProgressIndicator()); |
356 | } | 358 | } |
357 | 359 | ||
358 | - return Scrollbar( | ||
359 | - child: ListView.builder( | 360 | + return ListView.builder( |
360 | controller: scrollController, | 361 | controller: scrollController, |
361 | padding: widget.padding, | 362 | padding: widget.padding, |
362 | itemCount: pages.length, | 363 | itemCount: pages.length, |
@@ -370,7 +371,6 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -370,7 +371,6 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
370 | }, | 371 | }, |
371 | child: pages[index], | 372 | child: pages[index], |
372 | ), | 373 | ), |
373 | - ), | ||
374 | ); | 374 | ); |
375 | } | 375 | } |
376 | 376 | ||
@@ -554,7 +554,10 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -554,7 +554,10 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
554 | return Column( | 554 | return Column( |
555 | mainAxisAlignment: MainAxisAlignment.center, | 555 | mainAxisAlignment: MainAxisAlignment.center, |
556 | children: <Widget>[ | 556 | children: <Widget>[ |
557 | - Expanded(child: scrollView), | 557 | + Expanded( |
558 | + child: scrollController.hasClients | ||
559 | + ? Scrollbar(controller: scrollController, child: scrollView) | ||
560 | + : scrollView), | ||
558 | if (actions.isNotEmpty && widget.useActions) | 561 | if (actions.isNotEmpty && widget.useActions) |
559 | Material( | 562 | Material( |
560 | elevation: 4, | 563 | elevation: 4, |
@@ -568,6 +571,7 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -568,6 +571,7 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
568 | ), | 571 | ), |
569 | ), | 572 | ), |
570 | ), | 573 | ), |
574 | + ), | ||
571 | ) | 575 | ) |
572 | ], | 576 | ], |
573 | ); | 577 | ); |
@@ -643,13 +647,18 @@ class _PdfPreviewPage extends StatelessWidget { | @@ -643,13 +647,18 @@ class _PdfPreviewPage extends StatelessWidget { | ||
643 | @override | 647 | @override |
644 | Widget build(BuildContext context) { | 648 | Widget build(BuildContext context) { |
645 | final im = PdfRasterImage(page!); | 649 | final im = PdfRasterImage(page!); |
650 | + final scrollbarTrack = Theme.of(context) | ||
651 | + .scrollbarTheme | ||
652 | + .thickness | ||
653 | + ?.resolve({MaterialState.hovered}) ?? | ||
654 | + 12; | ||
646 | 655 | ||
647 | return Container( | 656 | return Container( |
648 | margin: pageMargin ?? | 657 | margin: pageMargin ?? |
649 | - const EdgeInsets.only( | ||
650 | - left: 8, | 658 | + EdgeInsets.only( |
659 | + left: 8 + scrollbarTrack, | ||
651 | top: 8, | 660 | top: 8, |
652 | - right: 8, | 661 | + right: 8 + scrollbarTrack, |
653 | bottom: 12, | 662 | bottom: 12, |
654 | ), | 663 | ), |
655 | decoration: pdfPreviewPageDecoration ?? | 664 | decoration: pdfPreviewPageDecoration ?? |
-
Please register or login to post a comment