Skip to content

[go_router][SelectionArea]: Assertion error on subroutes with SelectionArea and AdaptiveScaffold #151536

Open

Description

@Gustl22

Steps to reproduce

Execute the code sample (tested on web or macos)

Expected results

To not throw any error

Actual results

The following assertion was thrown during a scheduler callback:
RenderBox was not laid out: RenderFractionalTranslation#32ab0 NEEDS-LAYOUT NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 2165 pos 12: 'hasSize'

But nothing visually wrong.

Code sample

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

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    final router = GoRouter(
      // Default to the nested location
      // Or for a more realistic use-case, navigate to the url /a/b on the web
      initialLocation: '/root/sub',
      routes: [
        GoRoute(
          path: '/root',
          builder: (_, __) {
            // With selection area here, error will occur
            return const SelectionArea(
              child: Column(
                children: [
                  // Must be at least two selectable texts
                  Text('rootA'),
                  Text('rootB'),
                ],
              ),
            );
          },
          routes: [
            GoRoute(
              path: 'sub',
              builder: (_, __) {
                return const SelectionArea(
                  child: Column(
                    children: [
                      // Must be at least two selectable texts
                      Text('subA'),
                      Text('subB'),
                    ],
                  ),
                );
              },
            ),
          ],
        ),
      ],
    );
    return MaterialApp.router(
      routerConfig: router,
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs

Web:

Launching lib/test_main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
This app is linked to the debug service: ws://127.0.0.1:56108/pmYkwM1S-38=/ws
Debug service listening on ws://127.0.0.1:56108/pmYkwM1S-38=/ws
Debug service listening on ws://127.0.0.1:56108/pmYkwM1S-38=/ws

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
Assertion failed: file:///opt/homebrew/Caskroom/flutter/3.22.2/flutter/packages/flutter/lib/src/rendering/box.dart:2165:12
hasSize
"RenderBox was not laid out: RenderFractionalTranslation#d1f01 NEEDS-LAYOUT NEEDS-PAINT"

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3   assertFailed
packages/flutter/src/rendering/box.dart 2165:12                              get size
packages/flutter/src/rendering/proxy_box.dart 2936:29                        applyPaintTransform
packages/flutter/src/rendering/object.dart 3354:22                           getTransformTo
packages/flutter/src/rendering/paragraph.dart 2003:22                        getTransformTo
packages/flutter/src/widgets/selectable_region.dart 1925:8                   [_compareScreenOrder]
dart-sdk/lib/internal/sort.dart 69:51                                        _insertionSort
dart-sdk/lib/internal/sort.dart 58:7                                         _doSort
dart-sdk/lib/internal/sort.dart 33:5                                         sort
dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 471:12           sort]
packages/flutter/src/widgets/selectable_region.dart 1824:70                  <fn>
packages/flutter/src/widgets/selectable_region.dart 1824:75                  [_flushAdditions]
packages/flutter/src/widgets/selectable_region.dart 1818:7                   [_updateSelectables]
packages/flutter/src/widgets/selectable_region.dart 1797:9                   runScheduledTask
packages/flutter/src/scheduler/binding.dart 1392:7                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1326:11                          handleDrawFrame
packages/flutter/src/scheduler/binding.dart 1035:9                           <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:11      internalCallback
====================================================================================================

macOS:

Launching lib/test_main.dart on macOS in debug mode...
Building macOS application...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006030-0008311802D0001C, name:My Mac }
{ platform:macOS, arch:x86_64, id:00006030-0008311802D0001C, name:My Mac }
✓ Built build/macos/Build/Products/Debug/swi_toolbox.app
[IMPORTANT:flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm(66)] Using the Skia rendering backend (Metal).
Debug service listening on ws://127.0.0.1:56427/06ZpCvy9xOk=/ws
Syncing files to device macOS...

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
RenderBox was not laid out: RenderFractionalTranslation#32ab0 NEEDS-LAYOUT NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 2165 pos 12: 'hasSize'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack: 
#2      RenderBox.size (package:flutter/src/rendering/box.dart:2165:12)
#3      RenderFractionalTranslation.applyPaintTransform (package:flutter/src/rendering/proxy_box.dart:2936:24)
#4      RenderObject.getTransformTo (package:flutter/src/rendering/object.dart:3354:24)
#5      _SelectableFragment.getTransformTo (package:flutter/src/rendering/paragraph.dart:2003:22)
#6      MultiSelectableSelectionContainerDelegate._compareScreenOrder (package:flutter/src/widgets/selectable_region.dart:1925:9)
#7      Sort._insertionSort (dart:_internal/sort.dart:69:36)
#8      Sort._doSort (dart:_internal/sort.dart:58:7)
#9      Sort.sort (dart:_internal/sort.dart:33:5)
#10     ListBase.sort (dart:collection/list.dart:321:10)
#11     MultiSelectableSelectionContainerDelegate._flushAdditions (package:flutter/src/widgets/selectable_region.dart:1824:70)
#12     MultiSelectableSelectionContainerDelegate._updateSelectables (package:flutter/src/widgets/selectable_region.dart:1818:7)
#13     MultiSelectableSelectionContainerDelegate._scheduleSelectableUpdate.runScheduledTask (package:flutter/src/widgets/selectable_region.dart:1797:9)
#14     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
#15     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1326:11)
#16     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1035:9)
#17     PlatformDispatcher.scheduleWarmUpFrame.<anonymous closure> (dart:ui/platform_dispatcher.dart:837:16)
#21     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)
====================================================================================================
2024-07-10 15:23:49.211 swi_toolbox[3194:1234378] WARNING: Secure coding is automatically enabled for restorable state! However, not on all supported macOS versions of this application. Opt-in to secure coding explicitly by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState:.

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.6 23G5061b darwin-arm64, locale en-US)
    • Flutter version 3.22.2 on channel stable at /opt/homebrew/Caskroom/flutter/3.22.2/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (5 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/swi-oberhauser/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

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

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Community Edition (version 2024.1.4)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 80.0.2
    • Dart plugin version 241.17890.8

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6 23G5061b darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6 23G5061b darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 126.0.6478.127

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

! Doctor found issues in 2 categories

Related

#117527
#114254
#147452

Activity

  1. danagbemava-nc commented on Jul 11, 2024

    @danagbemava-nc
    Member

    Reproducible using the code sample provided above.

    flutter doctor -v
    [✓] Flutter (Channel stable, 3.22.2, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
        • Flutter version 3.22.2 on channel stable at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 761747bfc5 (5 weeks ago), 2024-06-05 22:15:13 +0200
        • Engine revision edd8546116
        • Dart version 3.4.3
        • DevTools version 2.34.3
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.1)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.90.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.92.0
    
    [✓] Connected device (5 available)
        • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.5.1 21F90
        • Dean’s iPad (mobile)            • 00008103-000825C811E3401E • ios            • iOS 17.5.1 21F90
        • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
        • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 14.4.1 23E224 darwin-arm64
        • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 126.0.6478.127
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.24.0-1.0.pre.78, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
        • Flutter version 3.24.0-1.0.pre.78 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 7de634bf25 (6 hours ago), 2024-07-10 20:52:29 -0400
        • Engine revision 6534fbf3c2
        • Dart version 3.6.0 (build 3.6.0-25.0.dev)
        • DevTools version 2.37.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.1)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.90.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.92.0
    
    [✓] Connected device (5 available)
        • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.5.1 21F90
        • Dean’s iPad (mobile)            • 00008103-000825C811E3401E • ios            • iOS 17.5.1 21F90
        • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
        • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 14.4.1 23E224 darwin-arm64
        • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 126.0.6478.127
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    
  2. added
    packageflutter/packages repository. See also p: labels.
    a: error messageError messages from the Flutter framework
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    f: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs
    and removed
    in triagePresently being triaged by the triage team
    on Jul 11, 2024
  3. stuartmorgan-g commented on Jul 16, 2024

    @stuartmorgan-g
    Contributor

    Framework team: is it expected that a package bug could cause this error? It's not clear to me from the stack.

  4. added
    P2Important issues not at the top of the work list
    on Jul 16, 2024
  5. 46 remaining items

  6. davidmigloz commented on Apr 10, 2026

    @davidmigloz
    Contributor

    Quick follow-up: the framework PR is up: #184900.

    The "Proposed framework fix" I sketched above didn't work out. Wrapping non-current route content in SelectionContainer.disabled at _ModalScopeState.build() can't reach selectables inside nested SelectionArea / SelectableRegion subtrees: those widgets install their own SelectionContainer(registrar: this, ...) inside the route (selectable_region.dart:1944) that shadows the disabled outer scope, so the route-level wrapper has no effect on the code path that actually crashes.

    The PR instead adds a surgical try/catch guard in both _compareScreenOrder overrides (selectable_region.dart and text.dart), catching StateError / AssertionError thrown from unlaid-out RenderBoxes and returning 0. It's a crash guard at sort time rather than a structural fix, the dead-zone behavior described in #182573 is unchanged, but it eliminates the crash across all three repro approaches (A / B / C) in https://github.com/davidmigloz/flutter_selection_crash. Full rationale, red/green test coverage, and the long-term structural-fix direction are in the PR description.

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

    P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkcustomer: castawayf: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIsfound in release: 3.22Found to occur in 3.22found in release: 3.24Found to occur in 3.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions