Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<StatefulWidget> createState() {
return PdfPageViewState();
Expand Down Expand Up @@ -861,25 +865,27 @@ class PdfPageViewState extends State<PdfPageView> {
child: Center(
child: Visibility(
visible: isVisible,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
_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<Color>(
_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)),
),
),
),
);
Expand Down
75 changes: 58 additions & 17 deletions packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<MyApp> {
/// final GlobalKey<SfPdfViewerState> _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();
}
Expand Down Expand Up @@ -3546,23 +3585,24 @@ class SfPdfViewerState extends State<SfPdfViewer> with WidgetsBindingObserver {
return Stack(
children: <Widget>[
_getEmptyContainer(),
LinearProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
_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<Color>(
_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),
),
],
);
}
Expand Down Expand Up @@ -3734,6 +3774,7 @@ class SfPdfViewerState extends State<SfPdfViewer> with WidgetsBindingObserver {
_selectedAnnotation,
_onAnnotationSelectionChanged,
_onStickyNoteAnnotationDoubleTapped,
loadingBuilder: widget.loadingBuilder,
);
final double pageSpacing =
index == _pdfViewerController._pageCount - 1
Expand Down