Skip to content

hasSize assertion fail in SelectableRegion within a background page #119776

@alexeyinkin

Description

@alexeyinkin

Steps to Reproduce

  1. Create a new Flutter project.
  2. Replace main.dart with the following.
  3. Run in Chrome.

Expected results: "foreground" text is visible, no exceptions

Actual results: "foreground" text is visible, two exceptions in console:

======== Exception caught by foundation library ====================================================
The following assertion was thrown while dispatching notifications for _SelectableRegionContainerDelegate:
Assertion failed: file:///home/alexey/snap/flutter/common/flutter/packages/flutter/lib/src/rendering/box.dart:2009:12
hasSize
"RenderBox was not laid out: RenderPhysicalModel#4cdfc 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 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
packages/flutter/src/rendering/box.dart 2009:12                               get size
packages/flutter/src/widgets/selection_container.dart 311:15                  get containerSize
packages/flutter/src/widgets/selectable_region.dart 1775:39                   [_updateHandleLayersAndOwners]
packages/flutter/src/widgets/selectable_region.dart 1761:5                    pushHandleLayers
packages/flutter/src/widgets/selection_container.dart 175:12                  pushHandleLayers
packages/flutter/src/widgets/selectable_region.dart 1124:5                    add
packages/flutter/src/rendering/selection.dart 195:7                           [_updateSelectionRegistrarSubscription]
packages/flutter/src/foundation/change_notifier.dart 381:24                   notifyListeners
packages/flutter/src/widgets/selectable_region.dart 1585:7                    [_updateSelectionGeometry]
packages/flutter/src/widgets/selectable_region.dart 1570:5                    didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1414:11                   didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1502:5                    [_updateSelectables]
packages/flutter/src/widgets/selectable_region.dart 1492:9                    <fn>
packages/flutter/src/scheduler/binding.dart 1289:15                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1227:9                            handleDrawFrame
packages/flutter/src/scheduler/binding.dart 942:7                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19       internalCallback
The _SelectableRegionContainerDelegate sending notification was: Instance of '_SelectableRegionContainerDelegate'
====================================================================================================

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
Assertion failed: file:///home/alexey/snap/flutter/common/flutter/packages/flutter/lib/src/rendering/box.dart:2009:12
hasSize
"RenderBox was not laid out: RenderPhysicalModel#4cdfc 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 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
packages/flutter/src/rendering/box.dart 2009:12                               get size
packages/flutter/src/widgets/selection_container.dart 311:15                  get containerSize
packages/flutter/src/widgets/selectable_region.dart 1775:39                   [_updateHandleLayersAndOwners]
packages/flutter/src/widgets/selectable_region.dart 1587:5                    [_updateSelectionGeometry]
packages/flutter/src/widgets/selectable_region.dart 1570:5                    didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1414:11                   didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1502:5                    [_updateSelectables]
packages/flutter/src/widgets/selectable_region.dart 1492:9                    <fn>
packages/flutter/src/scheduler/binding.dart 1289:15                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1227:9                            handleDrawFrame
packages/flutter/src/scheduler/binding.dart 942:7                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19       internalCallback
====================================================================================================

The exception is only thrown if the page with SelectableRegion is in the background. If the foreground page is deleted, everything works fine.

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: BackgroundSelectableRegionPage(),
    );
  }
}

final _focusNode = FocusNode();

class BackgroundSelectableRegionPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Navigator(
      pages: [
        MaterialPage(
          child: SelectableRegion(
            focusNode: _focusNode,
            selectionControls: materialTextSelectionControls,
            child: Scaffold(body: Text('background')),
          ),
        ),
        MaterialPage(
          child: Scaffold(body: Text('foreground')),
        ),
      ],
      onPopPage: (_, __) => false,
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel stable, 3.7.1, on Ubuntu 20.04.5 LTS 5.14.0-1056-oem, locale en_US.UTF-8)
    • Flutter version 3.7.1 on channel stable at /home/alexey/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7048ed95a5 (9 hours ago), 2023-02-01 09:07:31 -0800
    • Engine revision 800594f1f4
    • Dart version 2.19.1
    • DevTools version 2.20.1

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /home/alexey/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/linux#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2021.2)
    • Android Studio at /home/alexey/bin/android-studio
    • Flutter plugin version 71.0.2
    • Dart plugin version 212.5744
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.74.3)
    • VS Code at /usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 20.04.5 LTS 5.14.0-1056-oem
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consolef: routesNavigator, Router, and related APIs.f: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIsfound in release: 3.7Found to occur in 3.7found in release: 3.8Found to occur in 3.8frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions