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..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 @@ -71,8 +71,9 @@ class PdfPageView extends StatefulWidget { this.annotations, this.selectedAnnotation, this.onAnnotationSelectionChanged, - this.onStickyNoteDoubleTapped, - ) : super(key: key); + this.onStickyNoteDoubleTapped, { + this.loadingBuilder, + }) : super(key: key); /// Document ID of current pdf final String documentID; @@ -210,6 +211,9 @@ 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 State createState() { return PdfPageViewState(); @@ -861,25 +865,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)), + ), ), ), ); diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart index 2789bc5da..535b6db5e 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,40 @@ 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 SfPdfViewerState createState() => SfPdfViewerState(); } @@ -3546,23 +3585,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), + ), ], ); } @@ -3734,6 +3774,7 @@ class SfPdfViewerState extends State with WidgetsBindingObserver { _selectedAnnotation, _onAnnotationSelectionChanged, _onStickyNoteAnnotationDoubleTapped, + loadingBuilder: widget.loadingBuilder, ); final double pageSpacing = index == _pdfViewerController._pageCount - 1