Skip to content

Navigating with the selected text throws an exception when selected text is out of view #123527

@mkobuolys

Description

@mkobuolys

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Select one of the text lines and scroll the view until you see the "Go to next page" button. Notice, that the selected text should be out of view.
  3. Press the "Go to next page" button

Expected results: Exception should not be thrown.

Actual results: Exception is thrown

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter App',
      theme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      darkTheme: ThemeData(
        colorSchemeSeed: Colors.blue,
        useMaterial3: true,
        brightness: Brightness.dark,
      ),
      home: const MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView.separated(
        itemBuilder: (context, index) {
          if (index == 99) {
            return ElevatedButton(
              child: const Text('Go to next page'),
              onPressed: () => Navigator.of(context).push(
                MaterialPageRoute(
                  builder: (context) => const MyHomePage(),
                ),
              ),
            );
          }

          return SelectableText('This is text #$index');
        },
        separatorBuilder: (context, index) => const SizedBox(height: 8.0),
        itemCount: 100,
      ),
    );
  }
}
Logs
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#2e1d8](state: _OverlayEntryWidgetState#a895d):
'package:flutter/src/foundation/math.dart': Failed assertion: line 12 pos 10: 'min <= max && !max.isNaN && !min.isNaN': is not true.
math.dart:12
2

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.md

The relevant error-causing widget was
MaterialApp
main.dart:12
When the exception was thrown, this was the stack
#2      clampDouble
math.dart:12
#3      new TextSelectionToolbarAnchors.fromSelection
text_selection_toolbar_anchors.dart:54
#4      EditableTextState.contextMenuAnchors
editable_text.dart:2315
#5      new AdaptiveTextSelectionToolbar.editableText
adaptive_text_selection_toolbar.dart:130
#6      SelectableText._defaultContextMenuBuilder
selectable_text.dart:446
#7      EditableTextState._createSelectionOverlay.<anonymous closure>
editable_text.dart:3070
#8      SelectionOverlay.showToolbar.<anonymous closure>
text_selection.dart:1344
#9      ContextMenuController.show.<anonymous closure>
context_menu_controller.dart:59
#10     _OverlayEntryWidgetState.build
overlay.dart:259
#11     StatefulElement.build
framework.dart:5080
#12     ComponentElement.performRebuild
framework.dart:4968
#13     StatefulElement.performRebuild
framework.dart:5133
#14     Element.rebuild
framework.dart:4690
#15     StatefulElement.update
framework.dart:5156
#16     Element.updateChild
framework.dart:3660
#17     RenderObjectElement.updateChildren
framework.dart:6063
#18     MultiChildRenderObjectElement.update
framework.dart:6537
#19     Element.updateChild
framework.dart:3660
#20     ComponentElement.performRebuild
framework.dart:4993
#21     StatefulElement.performRebuild
framework.dart:5133
#22     Element.rebuild
framework.dart:4690
#23     StatefulElement.update
framework.dart:5156
#24     Element.updateChild
framework.dart:3660
#25     ComponentElement.performRebuild
framework.dart:4993
#26     Element.rebuild
framework.dart:4690
#27     ProxyElement.update
framework.dart:5301
#28     Element.updateChild
framework.dart:3660
#29     ComponentElement.performRebuild
framework.dart:4993
#30     Element.rebuild
framework.dart:4690
#31     ProxyElement.update
framework.dart:5301
#32     _InheritedNotifierElement.update
inherited_notifier.dart:107
#33     Element.updateChild
framework.dart:3660
#34     ComponentElement.performRebuild
framework.dart:4993
#35     StatefulElement.performRebuild
framework.dart:5133
#36     Element.rebuild
framework.dart:4690
#37     StatefulElement.update
framework.dart:5156
#38     Element.updateChild
framework.dart:3660
#39     ComponentElement.performRebuild
framework.dart:4993
#40     Element.rebuild
framework.dart:4690
#41     ProxyElement.update
framework.dart:5301
#42     _InheritedNotifierElement.update
inherited_notifier.dart:107
#43     Element.updateChild
framework.dart:3660
#44     ComponentElement.performRebuild
framework.dart:4993
#45     StatefulElement.performRebuild
framework.dart:5133
#46     Element.rebuild
framework.dart:4690
#47     StatefulElement.update
framework.dart:5156
#48     Element.updateChild
framework.dart:3660
#49     ComponentElement.performRebuild
framework.dart:4993
#50     Element.rebuild
framework.dart:4690
#51     ProxyElement.update
framework.dart:5301
#52     Element.updateChild
framework.dart:3660
#53     ComponentElement.performRebuild
framework.dart:4993
#54     StatefulElement.performRebuild
framework.dart:5133
#55     Element.rebuild
framework.dart:4690
#56     StatefulElement.update
framework.dart:5156
#57     Element.updateChild
framework.dart:3660
#58     SingleChildRenderObjectElement.update
framework.dart:6384
#59     Element.updateChild
framework.dart:3660
#60     SingleChildRenderObjectElement.update
framework.dart:6384
#61     Element.updateChild
framework.dart:3660
#62     ComponentElement.performRebuild
framework.dart:4993
#63     Element.rebuild
framework.dart:4690
#64     ProxyElement.update
framework.dart:5301
#65     Element.updateChild
framework.dart:3660
#66     ComponentElement.performRebuild
framework.dart:4993
#67     StatefulElement.performRebuild
framework.dart:5133
#68     Element.rebuild
framework.dart:4690
#69     BuildOwner.buildScope
framework.dart:2743
#70     WidgetsBinding.drawFrame
binding.dart:863
#71     RendererBinding._handlePersistentFrameCallback
binding.dart:381
#72     SchedulerBinding._invokeFrameCallback
binding.dart:1289
#73     SchedulerBinding.handleDrawFrame
binding.dart:1218
#74     SchedulerBinding._handleDrawFrame
binding.dart:1076
#75     _invoke (dart:ui/hooks.dart:145:13)
#76     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:338:5)
#77     _drawFrame (dart:ui/hooks.dart:112:31)
(elided 2 frames from class _AssertionError)
════════════════════════════════════════════════════════════════════════════════
Analyzing flutter_text_selection_issues...                              
No issues found! (ran in 1.0s)
[✓] Flutter (Channel stable, 3.7.7, on macOS 13.2.1 22D68 darwin-arm64, locale en-LT)
    • Flutter version 3.7.7 on channel stable at /Users/mkazlauskas/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2ad6cd72c0 (3 weeks ago), 2023-03-08 09:41:59 -0800
    • Engine revision 1837b5be5f
    • Dart version 2.19.4
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/mkazlauskas/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/mkazlauskas/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2021.3)
    • Android Studio at /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 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.76.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • iPhone 14 (mobile)          • ED472F44-9AF4-4D5F-ACA1-1A211E6D9B90 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 13.2.1 22D68 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 111.0.5563.110

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

• No issues found!
Screen.Recording.2023-03-27.at.10.58.05.mp4

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: crashStack traces logged to the consolef: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIsfound in release: 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9frameworkflutter/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

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions