Skip to content

Null check operator used on a null value in _globalToLocal during pointer-move on widget disposal #2569

Open

Description

@rumz26

Bug description

SfPdfViewer crashes with Null check operator used on a null value at pdfviewer.dart:2460 when a pointer-move is processed while the page is being disposed — _handlePointerMove → _globalToLocal applies ! to a RenderBox (from context.findRenderObject()) that is null during teardown. Same class as the fixed DataGrid #2561 and related to the open _getViewportGlobalRect crash #2565

Steps to reproduce

  1. Run the sample below on a physical Android device (the race is timing/device-dependent — more reproducible on slower / lower-RAM devices and in release mode).
  2. Place ~50 single-page PDFs in assets/pages/ (one PDF per page) so each PageView page hosts its own SfPdfViewer.
  3. Begin a pan/scroll gesture on a page and, while your finger is still moving, swipe horizontally to the next page so a pointer-move is still in flight as the current page's SfPdfViewer is being disposed.
  4. Repeat rapid swipes back and forth across several pages.
  5. Crash: Null check operator used on a null value in SfPdfViewerState._globalToLocal (reached via _handlePointerMove) — a RenderBox/BuildContext that is null during disposal is force-dereferenced.

Code sample

Code sample
import 'package:flutter/material.dart';
  import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

  void main() => runApp(const MaterialApp(home: ReaderDemo()));

  /// Paged reader: each PageView page hosts its own SfPdfViewer (one 
  single-page
  /// PDF per page), matching a magazine/e-paper reader. The viewer is created 
  and
  /// disposed as the user swipes. Crashes when a pointer-move gesture is 
  processed
  /// on a page whose SfPdfViewer is being torn down during a swipe.
  class ReaderDemo extends StatefulWidget {
    const ReaderDemo({super.key});
    @override
    State<ReaderDemo> createState() => _ReaderDemoState();
  }

  class _ReaderDemoState extends State<ReaderDemo> {
    final PageController _controller = PageController();

    // Replace with your own single-page PDFs in assets/pages/ (page_1.pdf … 
  page_50.pdf).
    final List<String> _pages =
        List<String>.generate(50, (i) => 'assets/pages/page_${i + 1}.pdf');

    @override                                                
    void dispose() {
      _controller.dispose();
      super.dispose();
    }
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Colors.black,                       
        body: PageView.builder(
          controller: _controller,
          itemCount: _pages.length,
          itemBuilder: (context, index) {
            // A fresh SfPdfViewer per page — created/disposed on every swipe.
            return SfPdfViewer.asset(
              _pages[index],
              key: ValueKey('pdf_$index'),
              pageLayoutMode: PdfPageLayoutMode.single,
              interactionMode: PdfInteractionMode.pan,
              canShowScrollHead: false,
              canShowScrollStatus: false,
              enableDoubleTapZooming: true,
            );
          },
        ),
      );
    }
  } ```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Stack Traces

<details open><summary>Stack Traces</summary>

```dart
[Add the Stack Traces here]

On which target platforms have you observed this bug?

Android

Flutter Doctor output

Doctor output
[Add your output here]

Activity

  1. AbinayaSF4962 commented on Nov 2, 2026

    @AbinayaSF4962

    Hi @rumz26 ,

    We were unable to reproduce the issue where the null check operator is used on a null value in _globalToLocal during pointer movement while the widget is being disposed on a physical Android device on our end.
    Please find the attached sample and screen recording that we used to validate the issue.
    Could you please review the attached sample and confirm whether the issue still occurs on your end? If the issue persists, kindly share the affected document, the modified version of the sample project, and the device details. This information will help us investigate and validate the issue further.

    sfpdfviewer_gh2569.mp4

    sfpdfviewer_gh2569.zip

    Regards,
    Abinaya E

  2. added
    pdf viewer
    waiting for customer response
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pdf viewerwaiting for customer response

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions