From 66dee4aad29ff5d8e3db60973fcda775e4224ce4 Mon Sep 17 00:00:00 2001 From: Nialixus <45191605+Nialixus@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:20:42 +0700 Subject: [PATCH 1/7] Add loadingBuilder parameter to PdfViewer --- .../lib/src/pdfviewer.dart | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart index 2789bc5da..166f6774b 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart @@ -189,6 +189,7 @@ class SfPdfViewer extends StatefulWidget { this.canShowHyperlinkDialog = true, this.enableHyperlinkNavigation = true, this.canShowTextSelectionMenu = true, + this.loadingBuilder, }) : _source = source, assert(pageSpacing >= 0), assert(!maxZoomLevel.isNaN), @@ -252,6 +253,7 @@ class SfPdfViewer extends StatefulWidget { this.maxZoomLevel = 3, this.interactionMode = PdfInteractionMode.selection, this.scrollDirection, + this.loadingBuilder, this.pageLayoutMode = PdfPageLayoutMode.continuous, this.currentSearchTextHighlightColor = const Color.fromARGB( 80, @@ -305,6 +307,7 @@ class SfPdfViewer extends StatefulWidget { this.canShowPageLoadingIndicator = true, this.canShowScrollStatus = true, this.onPageChanged, + this.loadingBuilder, this.enableDoubleTapZooming = true, this.enableTextSelection = true, this.onTextSelectionChanged, @@ -375,6 +378,7 @@ class SfPdfViewer extends StatefulWidget { this.canShowScrollHead = true, this.pageSpacing = 4, this.controller, + this.loadingBuilder, this.undoController, this.onZoomLevelChanged, this.canShowPageLoadingIndicator = true, @@ -453,6 +457,7 @@ class SfPdfViewer extends StatefulWidget { this.canShowScrollHead = true, this.pageSpacing = 4, this.controller, + this.loadingBuilder, this.undoController, this.onZoomLevelChanged, this.canShowPageLoadingIndicator = true, @@ -1191,6 +1196,8 @@ class SfPdfViewer extends StatefulWidget { /// ``` final bool canShowTextSelectionMenu; + final Widget Function(BuildContext context)? loadingBuilder; + @override SfPdfViewerState createState() => SfPdfViewerState(); } @@ -3546,23 +3553,24 @@ class SfPdfViewerState extends State with WidgetsBindingObserver { return Stack( children: [ _getEmptyContainer(), - LinearProgressIndicator( - valueColor: AlwaysStoppedAnimation( - _pdfViewerThemeData!.progressBarColor ?? - _effectiveThemeData!.progressBarColor ?? - _themeData!.colorScheme.primary, - ), - backgroundColor: - _pdfViewerThemeData!.progressBarColor != null - ? _pdfViewerThemeData!.progressBarColor!.withValues( - alpha: 0.2, - ) - : _effectiveThemeData!.progressBarColor != null - ? _effectiveThemeData!.progressBarColor!.withValues( - alpha: 0.2, - ) - : _themeData!.colorScheme.primary.withValues(alpha: 0.2), - ), + widget.loadingBuilder?.call(context) ?? + LinearProgressIndicator( + valueColor: AlwaysStoppedAnimation( + _pdfViewerThemeData!.progressBarColor ?? + _effectiveThemeData!.progressBarColor ?? + _themeData!.colorScheme.primary, + ), + backgroundColor: + _pdfViewerThemeData!.progressBarColor != null + ? _pdfViewerThemeData!.progressBarColor!.withValues( + alpha: 0.2, + ) + : _effectiveThemeData!.progressBarColor != null + ? _effectiveThemeData!.progressBarColor!.withValues( + alpha: 0.2, + ) + : _themeData!.colorScheme.primary.withValues(alpha: 0.2), + ), ], ); } From 0fc99ee80e70466823784597d66764e5102e6ee3 Mon Sep 17 00:00:00 2001 From: Nialixus <45191605+Nialixus@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:48:36 +0700 Subject: [PATCH 2/7] Add loadingBuilder support for custom loading widget --- .../lib/src/control/pdf_page_view.dart | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart index c6b7efc92..e2d2ca0f6 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart @@ -247,6 +247,7 @@ class PdfPageViewState extends State { late Size _originalPageSize; double _previousImageFactor = -1.0; bool _isTile = false; + Widget Function(BuildContext context)? loadingBuilder; /// Form fields in the page late List _formFields; @@ -861,25 +862,27 @@ class PdfPageViewState extends State { child: Center( child: Visibility( visible: isVisible, - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - _pdfViewerThemeData!.progressBarColor ?? - _effectiveThemeData!.progressBarColor ?? - (Theme.of(context).colorScheme.primary), - ), - backgroundColor: - _pdfViewerThemeData!.progressBarColor != null - ? _pdfViewerThemeData!.progressBarColor!.withValues( - alpha: 0.2, - ) - : _effectiveThemeData!.progressBarColor != null - ? _effectiveThemeData!.progressBarColor!.withValues( - alpha: 0.2, - ) - : (Theme.of( - context, - ).colorScheme.primary.withValues(alpha: 0.2)), - ), + child: + widget.loadingBuilder?.call(context) ?? + CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + _pdfViewerThemeData!.progressBarColor ?? + _effectiveThemeData!.progressBarColor ?? + (Theme.of(context).colorScheme.primary), + ), + backgroundColor: + _pdfViewerThemeData!.progressBarColor != null + ? _pdfViewerThemeData!.progressBarColor!.withValues( + alpha: 0.2, + ) + : _effectiveThemeData!.progressBarColor != null + ? _effectiveThemeData!.progressBarColor!.withValues( + alpha: 0.2, + ) + : (Theme.of( + context, + ).colorScheme.primary.withValues(alpha: 0.2)), + ), ), ), ); From 03572eb3e797b06e5d88083a7d50356e93ecc0d1 Mon Sep 17 00:00:00 2001 From: Nialixus <45191605+Nialixus@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:49:49 +0700 Subject: [PATCH 3/7] Change loadingBuilder to final in pdf_page_view.dart --- .../lib/src/control/pdf_page_view.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart index e2d2ca0f6..3d798b6c7 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart @@ -72,6 +72,7 @@ class PdfPageView extends StatefulWidget { this.selectedAnnotation, this.onAnnotationSelectionChanged, this.onStickyNoteDoubleTapped, + {this.loadingBuilder,} ) : super(key: key); /// Document ID of current pdf @@ -247,7 +248,7 @@ class PdfPageViewState extends State { late Size _originalPageSize; double _previousImageFactor = -1.0; bool _isTile = false; - Widget Function(BuildContext context)? loadingBuilder; + final Widget Function(BuildContext context)? loadingBuilder; /// Form fields in the page late List _formFields; @@ -863,7 +864,7 @@ class PdfPageViewState extends State { child: Visibility( visible: isVisible, child: - widget.loadingBuilder?.call(context) ?? + widget.loadingBuilder?.call(context) ?? CircularProgressIndicator( valueColor: AlwaysStoppedAnimation( _pdfViewerThemeData!.progressBarColor ?? From cd07a94fa94bef1985e4a4aa943ce0c43eec2638 Mon Sep 17 00:00:00 2001 From: Nialixus <45191605+Nialixus@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:51:13 +0700 Subject: [PATCH 4/7] Add loadingBuilder to PDF viewer widget --- packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart index 166f6774b..7195bd792 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart @@ -3742,6 +3742,7 @@ class SfPdfViewerState extends State with WidgetsBindingObserver { _selectedAnnotation, _onAnnotationSelectionChanged, _onStickyNoteAnnotationDoubleTapped, + loadingBuilder: widget.loadingBuilder, ); final double pageSpacing = index == _pdfViewerController._pageCount - 1 From 3ebdf8e7f55f0a78966782b5570384a872f9fe10 Mon Sep 17 00:00:00 2001 From: Nialixus <45191605+Nialixus@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:01:57 +0700 Subject: [PATCH 5/7] Fix formatting of constructor parameters in pdf_page_view.dart --- .../lib/src/control/pdf_page_view.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart index 3d798b6c7..a1c21a640 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart @@ -71,9 +71,9 @@ class PdfPageView extends StatefulWidget { this.annotations, this.selectedAnnotation, this.onAnnotationSelectionChanged, - this.onStickyNoteDoubleTapped, - {this.loadingBuilder,} - ) : super(key: key); + this.onStickyNoteDoubleTapped, { + this.loadingBuilder, + }) : super(key: key); /// Document ID of current pdf final String documentID; @@ -211,6 +211,8 @@ class PdfPageView extends StatefulWidget { /// Called when the user taps on the page. final Function(Offset, int) onTap; + final Widget Function(BuildContext context)? loadingBuilder; + @override State createState() { return PdfPageViewState(); @@ -248,7 +250,6 @@ class PdfPageViewState extends State { late Size _originalPageSize; double _previousImageFactor = -1.0; bool _isTile = false; - final Widget Function(BuildContext context)? loadingBuilder; /// Form fields in the page late List _formFields; From abb41d620d2b57bdb1828ec45495e052d366aaa6 Mon Sep 17 00:00:00 2001 From: Nialixus <45191605+Nialixus@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:21:41 +0700 Subject: [PATCH 6/7] Update pdf_page_view.dart --- .../lib/src/control/pdf_page_view.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart index a1c21a640..1143c0080 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdf_page_view.dart @@ -211,6 +211,7 @@ class PdfPageView extends StatefulWidget { /// Called when the user taps on the page. final Function(Offset, int) onTap; + /// Called to build the widget displayed while the PDF page is loading. final Widget Function(BuildContext context)? loadingBuilder; @override From 84d02139e88e68d43026c453eaf5714e2c710eb5 Mon Sep 17 00:00:00 2001 From: Nialixus <45191605+Nialixus@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:25:44 +0700 Subject: [PATCH 7/7] Add loadingBuilder for custom PDF loading widget Added a loadingBuilder property to allow custom loading widgets while a PDF page is loading. --- .../lib/src/pdfviewer.dart | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart index 7195bd792..535b6db5e 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart @@ -1196,6 +1196,38 @@ class SfPdfViewer extends StatefulWidget { /// ``` final bool canShowTextSelectionMenu; + /// Called to build a custom widget while a PDF page is loading. + /// + /// If this property is set, the returned widget will replace the default + /// page loading indicator in [SfPdfViewer]. + /// + /// Defaults to `null`. + /// + /// This example demonstrates how to show a custom loading widget in the [SfPdfViewer]. + /// + /// ```dart + /// class MyAppState extends State { + /// final GlobalKey _pdfViewerKey = GlobalKey(); + /// + /// @override + /// Widget build(BuildContext context) { + /// return Scaffold( + /// appBar: AppBar( + /// title: const Text('Syncfusion Flutter PDF Viewer'), + /// ), + /// body: SfPdfViewer.network( + /// 'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf', + /// key: _pdfViewerKey, + /// loadingBuilder: (context) { + /// return const Center( + /// child: CircularProgressIndicator(), + /// ); + /// }, + /// ), + /// ); + /// } + /// } + /// ``` final Widget Function(BuildContext context)? loadingBuilder; @override