Repository navigation
Failed assertion when trying to set caret position to text position that is not visible #122443
Copy link
Copy link
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleStack traces logged to the consolec: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityfound in release: 3.7Found to occur in 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9Found to occur in 3.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
════════ Exception caught by scheduler library ═════════════════════════════════
The following assertion was thrown during a scheduler callback:
'package:flutter/src/widgets/editable_text.dart': Failed assertion: line 3549 pos 16: '!composingRange.isValid || composingRange.isCollapsed': is not true.
editable_text.dart:3549
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
When the exception was thrown, this was the stack
#2 EditableTextState._updateComposingRectIfNeeded
editable_text.dart:3549
#3 EditableTextState._updateComposingRectIfNeeded.<anonymous closure>
editable_text.dart:3555
#4 SchedulerBinding._invokeFrameCallback
binding.dart:1289
#5 SchedulerBinding.handleDrawFrame
binding.dart:1227
#6 SchedulerBinding._handleDrawFrame
binding.dart:1076
#7 _invoke (dart:ui/hooks.dart:145:13)
#8 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:338:5)
#9 _drawFrame (dart:ui/hooks.dart:112:31)
(elided 2 frames from class _AssertionError)
Steps to Reproduce
Create a TextField that does not allow multi-line input (i.e. don't set maxLines: null).
Then set the text of the TextField to a string that contains a newline (so that part of the text will not be visible in the text widget), using setText (shown below).
This method tries to set the caret position to a position past the end of the visible input in this case, which triggers the exception.
final controller = TextEditingController();
setText(String text) {
controller.text = text;
// Move cursor to end of text
controller.selection = TextSelection.fromPosition(
TextPosition(offset: controller.text.length),
);
}Expected results:
Probably the TextPosition should be set to the closest visible position, rather than failing an assertion if the requested position is not visible.
Actual results:
The above error
[luke@fedora clickdating_flutter]$ flutter doctor -v
[✓] Flutter (Channel stable, 3.7.5, on Fedora Linux 36 (Workstation Edition)
6.1.14-100.fc36.x86_64, locale en_US.utf8)
• Flutter version 3.7.5 on channel stable at /opt/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c07f788888 (2 weeks ago), 2023-02-22 17:52:33 -0600
• Engine revision 0f359063c4
• Dart version 2.19.2
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /home/luke/Android/Sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build
11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• clang version 14.0.5 (Fedora 14.0.5-2.fc36)
• cmake version 3.25.2
• ninja version 1.10.2
• pkg-config version 1.8.0
[✓] Android Studio (version 2021.3)
• Android Studio at /opt/android-studio
• Flutter plugin version 71.0.3
• Dart plugin version 213.7433
• Java version OpenJDK Runtime Environment (build
11.0.13+0-b1751.21-8125866)
[✓] VS Code (version 1.76.0)
• VS Code at /usr/share/code
• Flutter extension version 3.60.0
[✓] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 13
(API 33) (emulator)
• Linux (desktop) • linux • linux-x64 • Fedora
Linux 36 (Workstation Edition) 6.1.14-100.fc36.x86_64
• Chrome (web) • chrome • web-javascript • Google
Chrome 110.0.5481.177
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleStack traces logged to the consolec: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityfound in release: 3.7Found to occur in 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9Found to occur in 3.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
darshankawar commentedon Mar 13, 2023
Thanks for the report @lukehutch
I am unable to replicate this error on latest stable and master version. Based on the steps to replicate you provided, I came up with below runnable code sample with which I couldn't replicate the reported error.
code sample
If above doesn't represent the replication properly, please provide us the correct code sample and steps to replicate that we can use to verify this issue further.
A similar issue but seems to be related to localized text: #110343
lukehutch commentedon Mar 14, 2023
Sorry, I should have provided the full repro code myself... thanks for trying to recreate this.
Try replacing the
TextFieldin your example withMyTextField:The
autofocus: truepart is important, so that the caret is already in the text field when you interact with the contents. Do not click on the Android emulator window, just give the window focus by clicking on the titlebar, or use Alt+Tab to focus the emulator. Clicking on the text field seems to correctly set the caret position to the end of the visible text, which eliminates the problem.Then, to reproduce the issue, hit the Left arrow key one or more times. This tries to move the cursor position, which is off the visible screen, and gives the error shown in the original bug report.
Reproduced on Flutter 3.7.7.
darshankawar commentedon Mar 14, 2023
Thanks for the detailed update. Using the code snippet provided above, I was able to replicate the reported error using latest master as well as stable version. However, this error per my verification only occurs on Android, as trying the same steps using iOS simulator doesn't throw the error.
runnable code sample
console error log
Exact steps to replicate:
Multiline.Also observed that, in subsequent tries to replicate, we don't need to repeat step 2 and 3. Upon hot restarting the app, it throws the error directly.
stable, master flutter doctor -v
13 remaining items
flutter-triage-bot commentedon Aug 8, 2023
The
fyi-frameworklabel is redundant with theteam-frameworklabel.tspence commentedon Aug 27, 2025
Checking in - my team has hit this issue recently in our Android mobile app editor, and I'm curious if this is on the schedule for a fix, or whether there's a workaround we can use to prevent it?
Renzo-Olivares commentedon Aug 27, 2025
Hello @tspence are you still able to reproduce this issue using the sample code in #122443 (comment)? If so what branch are you on. I tried reproducing this myself on the
masterbranch using the sample code but was not able to reproduce the assertion error. There is still potentially an issue where the text position gets set to a non-visible position, but I am not seeing failed assertions on my end.tspence commentedon Aug 28, 2025
Thanks so much for the quick reply @Renzo-Olivares ! Our issue is the "caret set beyond end of text" issue. We're using flutter and one of our QA analysts demonstrated editing in a text box and scrolling a selection beyond the end of the text, which generated a grey screen. I'll ask the developers to share some more details here as soon as possible.
Renzo-Olivares commentedon Aug 28, 2025
Hi @tspence thanks for the clarification, just to make sure I understand correctly the issue your experiencing is that the caret is being set beyond the end of the visible text, but you are not experiencing an assertion error being triggered. Thank you for any additional details!
LongCatIsLooong commentedon Aug 29, 2025
The assert is removed because it had false positives: #110343.
Renzo-Olivares commentedon Aug 29, 2025
@LongCatIsLooong Thank you for the additional context!