Repository navigation
TextField with TextAlign.right throws Failed assertion: line 206 pos 12: 'isValid': is not true. #139201
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: 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 consolefound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17Found to occur in 3.17has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagesp: 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.team-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
Create a CupertinoTextField object with TextAlign.right, enter a text with several letters, and press the up and down keys to go to the beginning or end of the text.
Expected results
The cursor moving at the beginning or end of the text.
Actual results
This message:
══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════
The following assertion was thrown during method call TextInputClient.performSelectors:
'package:flutter/src/rendering/editable.dart': Failed assertion: line 206 pos 12: 'isValid': is not
true.
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 VerticalCaretMovementRun.movePrevious (package:flutter/src/rendering/editable.dart:206:12)
#3 _UpdateTextSelectionVerticallyAction.invoke (package:flutter/src/widgets/editable_text.dart:5557:61)
#4 _OverridableContextAction.invokeDefaultAction (package:flutter/src/widgets/actions.dart:1811:28)
#5 _OverridableActionMixin.invoke (package:flutter/src/widgets/actions.dart:1676:9)
#6 Action._invoke (package:flutter/src/widgets/actions.dart:336:19)
#7 ActionDispatcher.invokeAction (package:flutter/src/widgets/actions.dart:641:19)
#8 Actions.invoke.<anonymous closure> (package:flutter/src/widgets/actions.dart:963:48)
#9 Actions._visitActionsAncestors (package:flutter/src/widgets/actions.dart:745:18)
#10 Actions.invoke (package:flutter/src/widgets/actions.dart:957:30)
#11 EditableTextState.performSelector (package:flutter/src/widgets/editable_text.dart:4347:17)
#12 ListBase.forEach (dart:collection/list.dart:51:13)
#13 TextInput._handleTextInputInvocation (package:flutter/src/services/text_input.dart:1880:19)
#14 TextInput._loudlyHandleTextInputInvocation (package:flutter/src/services/text_input.dart:1759:20)
#15 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:559:55)
#16 MethodChannel.setMethodCallHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:552:34)
#17 _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:567:35)
#18 _invoke2 (dart:ui/hooks.dart:344:13)
#19 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
#20 _Channel.push (dart:ui/channel_buffers.dart:135:31)
#21 ChannelBuffers.push (dart:ui/channel_buffers.dart:343:17)
#22 PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:722:22)
#23 _dispatchPlatformMessage (dart:ui/hooks.dart:257:31)
(elided 2 frames from class _AssertionError)
Code sample
Code sample
CupertinoTextField(
textAlign: TextAlign.right,
controller: widget.controller,
)Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.16.1, on macOS 14.0 23A344 darwin-arm64, locale en-ES)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
✗ 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.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.84.2)
[✓] VS Code (version 1.85.0-insider)
[✓] Connected device (2 available)
[✓] Network resources
! Doctor found issues in 1 category.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: 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 consolefound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17Found to occur in 3.17has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagesp: 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.team-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Activity
darshankawar commentedon Nov 29, 2023
Thanks for the report @optimisme
I was able to replicate the reported error and it seems to be only occuring when using
textAlign: rightstable, master flutter doctor -v
There's another related issue logged, but for desktop: #139196
[-]CupertinoTextField TextAlign.right[/-][+][Cupertino]: CupertinoTextField with `TextAlign.right` throws `Failed assertion: line 206 pos 12: 'isValid': is not true.`[/+]19 remaining items
TextAlign.rightthrows Failed assertion: line 218 pos 12: 'isValid': is not true. #165979 as a duplicate of this issuerekire commentedon Mar 27, 2025
@LongCatIsLooong you might want to update the tags. It is still present and not really related to exclusive related to Cupertino. The P2 means basically nobody will fix it soonish right?
Can you explain why this happens? I looked into the code and didn't really understand what is going on.
[-][Cupertino]: CupertinoTextField with `TextAlign.right` throws `Failed assertion: line 206 pos 12: 'isValid': is not true.`[/-][+]TextField with `TextAlign.right` throws `Failed assertion: line 206 pos 12: 'isValid': is not true.`[/+]maheshj01 commentedon Mar 27, 2025
This reproduces with textfield in general
from triage: #165979 (comment)
LongCatIsLooong commentedon Mar 27, 2025
So the tldr is that the
TextPainterimplementation detail that theVerticalCaretMovementRunrelies on is changed, soVerticalCaretMovementRun.isValidis always false when the text align is not.left.The current implementation marks a
VerticalCaretMovementRunas invalid when thelineMetricsare not identical:But I think I changed it at some point that
computeLineMetricswould return a different List instance every time if textAlign is not.leftso it's always false.The
isValidindicates whether the underlying text layout has changed but the implementation is really a hack since we can't really get that information without extensively compare the current text layout and the text layout before.We needed that information so that we can "reset" a vertical cursor run (see the documentation here).
victorsanni commentedon Jun 8, 2025
Still reproducible on
master.ali-1989 commentedon Nov 3, 2025
this bug still exist on flutter 3.35
Cache the paint offset adjusted line metrics in TextPainter (flutter#…
github-actions commentedon Oct 9, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.