Skip to content

[Flutter PDF Viewer][Android] RenderBox was not laid out in _getViewportGlobalRect #2565

Open

Description

@jamespauly

Bug description

Description

We’re seeing a production layout exception in SfPdfViewer:

Bad state: RenderBox was not laid out: RenderTransform

The exception originates in SfPdfViewerState._getViewportGlobalRect() while the viewer rebuilds through a LayoutBuilder.

Environment

  • syncfusion_flutter_pdfviewer: 34.2.6 — current app dependency
  • Flutter: 3.47.2, Shorebird engine
  • Dart: 3.13.2
  • Device: Google Pixel 9, physical device
  • OS: Android 17
  • Build mode: Release
  • App version: 5.0.0, build 100
  • Shorebird patch: base, no patch applied

Stack trace

StateError: Bad state: RenderBox was not laid out: RenderTransform

RenderBox.size
RenderTransform._effectiveTransform
RenderTransform.applyPaintTransform
RenderObject.getTransformTo
RenderBox.localToGlobal
SfPdfViewerState._getViewportGlobalRect
SfPdfViewerState.build.
_LayoutBuilderElement._rebuildWithConstraints.updateChildCallback

The captured Syncfusion frames reference pdfviewer.dart lines 3581 and 3742.

Viewer configuration

The viewer displays bundled PDF assets inside a Scaffold with bounded
constraints. Pages are opened using MaterialPageRoute.

SfPdfViewer.asset(
documentAsset,
controller: controller,
canShowScrollHead: false,
canShowScrollStatus: false,
canShowPaginationDialog: false,
canShowSignaturePadDialog: false,
enableTextSelection: false,
interactionMode: PdfInteractionMode.pan,
pageLayoutMode: PdfPageLayoutMode.continuous,
scrollDirection: PdfScrollDirection.vertical,
pageSpacing: 12,
maxZoomLevel: 5,
)

Observed conditions

We have not yet established deterministic reproduction steps.

The session included multiple background/foreground transitions and
low-memory notifications before the exception. The same layout error
appeared more than once in the session.

We cannot confirm whether navigation, zooming, or resuming the app was
the immediate trigger.

Expected behavior

The PDF viewer should handle navigation and layout changes without
reading geometry from render objects whose layout is incomplete.

Possible cause

In _getViewportGlobalRect(), localToGlobal(Offset.zero) is called
before the viewer's hasSize check.

The stack suggests that coordinate conversion traverses an ancestor
RenderTransform that requires its size before layout has completed.
Checking only the viewport's own hasSize may therefore be insufficient.

Could you investigate whether viewport geometry should be calculated
after layout completes, or otherwise guarded against unfinished
ancestor layout?

Please let us know whether this is a known issue, whether a release
addresses it, or whether there is a recommended workaround.

Steps to reproduce

This was captured in production; we have not established a reliable reproduction yet.

Suggested sequence to investigate:

  1. On Android, open a bundled PDF using SfPdfViewer.asset inside a MaterialPageRoute.
  2. Use continuous page layout with vertical scrolling.
  3. Scroll through the document and pinch to zoom.
  4. Put the app in the background, then return to it.
  5. Repeat background/foreground transitions and navigate away from and back to the PDF page.

Observed result:
The viewer intermittently throws:
“Bad state: RenderBox was not laid out: RenderTransform”
from SfPdfViewerState._getViewportGlobalRect().

Expected result:
The PDF remains usable without a layout exception.

The affected session included background/foreground transitions and earlier low-memory warnings. We cannot confirm the exact action that triggered the exception.

Code sample

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

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

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

  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('PDF layout reproduction')),
    body: Center(
      child: FilledButton(
        onPressed: () => Navigator.of(context).push(
          MaterialPageRoute<void>(
            builder: (_) => const PdfPage(),
          ),
        ),
        child: const Text('Open PDF'),
      ),
    ),
  );
}

class PdfPage extends StatefulWidget {
  const PdfPage({super.key});

  @override
  State<PdfPage> createState() => _PdfPageState();
}

class _PdfPageState extends State<PdfPage> {
  final PdfViewerController _controller = PdfViewerController();

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(
      title: const Text('PDF document'),
      actions: [
        IconButton(
          tooltip: 'Reset zoom',
          onPressed: () => _controller.zoomLevel = 1,
          icon: const Icon(Icons.fit_screen),
        ),
      ],
    ),
    body: SafeArea(
      child: Stack(
        children: [
          Positioned.fill(
            child: SfPdfViewer.asset(
              'assets/sample.pdf',
              controller: _controller,
              canShowScrollHead: false,
              canShowScrollStatus: false,
              canShowPaginationDialog: false,
              canShowSignaturePadDialog: false,
              enableTextSelection: false,
              interactionMode: PdfInteractionMode.pan,
              pageLayoutMode: PdfPageLayoutMode.continuous,
              scrollDirection: PdfScrollDirection.vertical,
              pageSpacing: 12,
              maxZoomLevel: 5,
            ),
          ),
        ],
      ),
    ),
  );
}

Screenshots or Video

Screenshots / Video demonstration

I don't have anything as I cannot reproduce on the devices I own. I'm getting these error is Sentry.

Stack Traces

Stack Traces

StateError: Bad state: RenderBox was not laid out: RenderTransform#aeaa4

#0 RenderBox.size
package:flutter/src/rendering/box.dart:2304

#1 RenderTransform._effectiveTransform
package:flutter/src/rendering/proxy_box.dart:2700

#2 RenderTransform.applyPaintTransform
package:flutter/src/rendering/proxy_box.dart:2783

#3 RenderObject.getTransformTo
package:flutter/src/rendering/object.dart:3730

#4 RenderBox.localToGlobal
package:flutter/src/rendering/box.dart:3114

#5 SfPdfViewerState._getViewportGlobalRect
package:syncfusion_flutter_pdfviewer/src/pdfviewer.dart:3581

#6 SfPdfViewerState.build.
package:syncfusion_flutter_pdfviewer/src/pdfviewer.dart:3742

#7 _LayoutBuilderElement._rebuildWithConstraints.updateChildCallback
package:flutter/src/widgets/layout_builder.dart:232

#8 BuildOwner.buildScope
package:flutter/src/widgets/framework.dart:3114

#9 _LayoutBuilderElement._rebuildWithConstraints
package:flutter/src/widgets/layout_builder.dart:270

#10 RenderAbstractLayoutBuilderMixin.layoutCallback
package:flutter/src/widgets/layout_builder.dart:333

#11 RenderObjectWithLayoutCallbackMixin.runLayoutCallback.
package:flutter/src/rendering/object.dart:4313

#12 RenderObject.invokeLayoutCallback.
package:flutter/src/rendering/object.dart:3042

#13 PipelineOwner._enableMutationsToDirtySubtrees
package:flutter/src/rendering/object.dart:1223

#14 RenderObject.invokeLayoutCallback
package:flutter/src/rendering/object.dart:3041

#15 RenderObjectWithLayoutCallbackMixin.runLayoutCallback
package:flutter/src/rendering/object.dart:4313

#16 _RenderLayoutBuilder.performLayout
package:flutter/src/widgets/layout_builder.dart:447

#17 RenderObject.layout
package:flutter/src/rendering/object.dart:2923

[Remaining Flutter layout and frame-scheduling frames omitted]

On which target platforms have you observed this bug?

Android

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.47.2, on macOS 27.0.1 26A434 darwin-arm64, locale en-US) [341ms]
    • Flutter version 3.47.2 on channel stable at /opt/homebrew/share/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d3b14c8769 (9 weeks ago), 2026-08-26 16:07:51 -0700
    • Engine revision a804b26164
    • Dart version 3.13.2
    • DevTools version 2.60.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop,
      enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use,
      no-enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging,
      enable-uiscene-migration

[!] Android toolchain - develop for Android devices (Android SDK version 37.0.0) [520ms]
    • Android SDK at /Users/xx/Library/Android/sdk
    • Emulator version 37.2.12.0 (build_id 16428233) (CL:N/A)
    • Platform android-37.0, build-tools 37.0.0
    • ANDROID_HOME = /Users/xx/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/xx/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 25.0.3+-15898627-b508.16)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 27.1) [770ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 27A9275
    • CocoaPods version 1.17.0

[✓] Chrome - develop for the web [6ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (3 available) [6.3s]
    • John Doe iPhone 17 (wireless) (mobile) • xxxxxx • ios            • iOS 27.0.1 24A446
    • macOS (desktop)                     • macos                     • darwin-arm64   • macOS 27.0.1 26A434
      darwin-arm64
    • Chrome (web)                        • chrome                    • web-javascript • Google Chrome
      156.0.8078.47

[✓] Network resources [146ms]
    • All expected network resources are available.

Activity

  1. added
    pdf viewer
    open
    on Oct 27, 2026
  2. lingeshwaran-sf4984 commented on Oct 27, 2026

    @lingeshwaran-sf4984

    Hi @jamespauly ,
    We were able to reproduce the reported issue where page text is not rendered properly during scrolling and pinch-to-zoom operations on the Android platform. We are currently validating this issue and will provide further updates on October 29, 2026.

    Regards,
    Lingeshwaran S

  3. lingeshwaran-sf4984 commented on Oct 29, 2026

    @lingeshwaran-sf4984

    Hi @jamespauly ,
    Based on our investigation, the issue does not occur on all Android devices and appears to be device-specific. Due to the complexity involved in validation, we require additional time to thoroughly investigate the issue. We will share our findings and provide an update by November 2, 2026.

    Regards,
    Lingeshwaran S

  4. AbinayaSF4962 commented on Nov 2, 2026

    @AbinayaSF4962

    Hi @jamespauly ,

    We have confirmed that the issue where layout exception occurs during route transition and gesture navigation using Syncfusion Flutter PDF Viewer is a defect in our product and logged a bug report for the same. The fix for this issue will be included in the weekly release scheduled for November 10, 2026.
    Please use the feedback link to track the status of the bug, Layout Exception in SfPdfViewer During Route Navigation, App Lifecycle Changes, and Gesture Interac…
    Disclaimer: "Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization."

    Regards,
    Abinaya E

  5. jamespauly commented on Nov 2, 2026

    @jamespauly
    Author

    5. Hi @jamespauly ,
    We have confirmed that the issue where layout exception occurs during route transition and gesture navigation using Syncfusion Flutter PDF Viewer is a defect in our product and logged a bug report for the same. The fix for this issue will be included in the weekly release scheduled for November 10, 2026.
    Please use the feedback link to track the status of the bug, Layout Exception in SfPdfViewer During Route Navigation, App Lifecycle Changes, and Gesture Interac…
    Disclaimer: "Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization."
    Regards,
    Abinaya E

    Thank you for the quick turnaround!

  6. added
    bug
    follow-up scheduled
    and removed
    open
    on Nov 3, 2026
  7. lingeshwaran-sf4984 commented on Nov 3, 2026

    @lingeshwaran-sf4984

    Hi @jamespauly ,
    Thank you for your response. Please get in touch with us if you would require any further assistance.

    Regards,
    Lingeshwaran S

  8. lingeshwaran-sf4984 commented on Nov 10, 2026

    @lingeshwaran-sf4984

    Hi @jamespauly ,
    We would like to inform you that the weekly release has been rescheduled to tomorrow. The fix will be included in that release, and we appreciate your patience and understanding.

    Regards,
    Lingeshwaran S

  9. lingeshwaran-sf4984 commented on Nov 11, 2026

    @lingeshwaran-sf4984

    Hi @jamespauly ,
    We have resolved an issue that caused a layout exception in SfPdfViewer during route transitions and gesture navigation. The fix has been included in the latest weekly release.
    Package link: syncfusion_flutter_pdfviewer v35.1.46

    Root cause: _getViewportGlobalRect()calls localToGlobal() inside the LayoutBuildercallback while Flutter is still performing layout. During this process, an ancestor RenderTransformis in the NEEDS-LAYOUTstate, causing localToGlobal()to throw "RenderBox was not laid out: RenderTransform".
    We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you require any further assistance.
    Regards,
    Lingeshwaran S

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

    bugfollow-up scheduledpdf viewer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions