Skip to content

SfPdfViewer throws error when used inside a nested Navigator #2366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LiangShaing opened this issue Jun 4, 2025 · 1 comment
Open

SfPdfViewer throws error when used inside a nested Navigator #2366

LiangShaing opened this issue Jun 4, 2025 · 1 comment
Labels
pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds.

Comments

@LiangShaing
Copy link

LiangShaing commented Jun 4, 2025

Hi Syncfusion team,

I'm encountering an issue when wrapping SfPdfViewer.memory inside a nested Navigator. When I try to use built-in features like page navigation, I consistently receive the following error:

Failed assertion: line 5646 pos 12: '_history.isNotEmpty': is not true.

Here's a simplified version of the code:

Navigator( key: navigationPossKey, onGenerateInitialRoutes: (navigatorState, initialRoute) { return [ MaterialPageRoute( builder: (context) => Builder( builder: (context) { return SfPdfViewer.memory( _pdfBytes!, ); }, ), ) ]; }, )

I suspect the internal use of Navigator within the PDF viewer is conflicting with the custom navigation context created by the nested Navigator. This causes the internal history stack to behave unexpectedly or break altogether.

Would it be possible to improve support for nested navigators or expose some options to disable internal navigation behavior? Alternatively, is there a recommended approach for using SfPdfViewer inside a tab/page structure with a nested navigator?

Thanks in advance!

@immankumarsync
Copy link
Contributor

Hi @LiangShaing,
We are unable to replicate the reported behavior using the code snippet below. Please find the sample and the video recording attached.

Details

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: HomePage());
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: TextButton(
          onPressed: () async {
            final ByteData data = await rootBundle.load(
              'assets/flutter-succinctly.pdf',
            );
            if (context.mounted) {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) {
                    return PDFViewerPage(pdfData: data.buffer.asUint8List());
                  },
                ),
              );
            }
          },
          child: const Text('Open PDF'),
        ),
      ),
    );
  }
}

class PDFViewerPage extends StatefulWidget {
  const PDFViewerPage({super.key, required this.pdfData});

  final Uint8List pdfData;

  @override
  State<PDFViewerPage> createState() => _PDFViewerPageState();
}

class _PDFViewerPageState extends State<PDFViewerPage> {
  final GlobalKey<NavigatorState> navigationPossKey =
      GlobalKey<NavigatorState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Navigator(
        key: navigationPossKey,
        onGenerateInitialRoutes: (navigatorState, initialRoute) {
          return [
            MaterialPageRoute(
              builder: (context) => Builder(
                builder: (context) {
                  return SfPdfViewer.memory(
                    widget.pdfData,
                    pageLayoutMode: PdfPageLayoutMode.single,
                  );
                },
              ),
            ),
          ];
        },
      ),
    );
  }
}

Please share the below details to replicate the issue at our end.

  1. Simple sample or complete code snippet
  2. Platform in which the issue ocurs
  3. flutter doctor -v report

Sample.zip

@Deepak1799 Deepak1799 added pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds. labels Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

3 participants