Skip to content

TextField with TextAlign.right throws Failed assertion: line 206 pos 12: 'isValid': is not true. #139201

Closed

Description

@optimisme

Is there an existing issue for this?

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.

Activity

  1. darshankawar commented on Nov 29, 2023

    @darshankawar
    Member

    Thanks for the report @optimisme
    I was able to replicate the reported error and it seems to be only occuring when using textAlign: right

    stable, master flutter doctor -v
    [!] Flutter (Channel stable, 3.16.0, on macOS 12.2.1 21D62 darwin-x64, locale
        en-GB)
        • Flutter version 3.16.0 on channel stable at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision db7ef5bf9f (12 days ago), 2023-11-15 11:25:44 -0800
        • Engine revision 74d16627b9
        • Dart version 3.2.0
        • DevTools version 2.28.2
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    [!] Flutter (Channel master, 3.17.0-17.0.pre.49, on macOS 12.2.1 21D62
        darwin-x64, locale en-GB)
        • Flutter version 3.17.0-17.0.pre.49 on channel master at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 0233e93853 (61 minutes ago), 2023-11-28 23:30:21 -0500
        • Engine revision 9a840e8dba
        • Dart version 3.3.0 (build 3.3.0-170.0.dev)
        • DevTools version 2.30.0-dev.4
        • 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 30.0.3)
        • Android SDK at /Users/dhs/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 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 13C100
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
        • IntelliJ at /Applications/IntelliJ IDEA.app
        • Flutter plugin version 65.1.4
        • Dart plugin version 213.7228
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (3 available)
        • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
          • iOS 15.3.1 19D52
        • macOS (desktop)           • macos                                    •
          darwin-x64     • macOS 12.2.1 21D62 darwin-x64
        • Chrome (web)              • chrome                                   •
          web-javascript • Google Chrome 109.0.5414.119
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
          
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
    
    

    There's another related issue logged, but for desktop: #139196

  2. added
    a: text inputEntering text in a text field or keyboard related problems
    c: crashStack traces logged to the console
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: cupertino_uicupertino_ui package in flutter/packages
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Nov 29, 2023
  3. changed the title [-]CupertinoTextField TextAlign.right[/-] [+][Cupertino]: CupertinoTextField with `TextAlign.right` throws `Failed assertion: line 206 pos 12: 'isValid': is not true.`[/+] on Nov 29, 2023
  4. added and removed
    team-designOwned by Design Languages team
    on Nov 29, 2023
  5. added
    team-designOwned by Design Languages team
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    and removed on Nov 29, 2023
  6. 19 remaining items

  7. rekire commented on Mar 27, 2025

    @rekire
    Contributor

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

  8. changed the title [-][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.`[/+] on Mar 27, 2025
  9. maheshj01 commented on Mar 27, 2025

    @maheshj01
    Member

    This reproduces with textfield in general
    from triage: #165979 (comment)

  10. LongCatIsLooong commented on Mar 27, 2025

    @LongCatIsLooong
    Contributor

    So the tldr is that the TextPainter implementation detail that the VerticalCaretMovementRun relies on is changed, so VerticalCaretMovementRun.isValid is always false when the text align is not .left.

    The current implementation marks a VerticalCaretMovementRun as invalid when the lineMetrics are not identical:

      bool get isValid => !identical(_editable._textPainter.computeLineMetrics(), _lineMetrics);

    But I think I changed it at some point that computeLineMetrics would return a different List instance every time if textAlign is not .left so it's always false.

    The isValid indicates 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).

  11. victorsanni commented on Jun 8, 2025

    @victorsanni
    Contributor

    Still reproducible on master.

  12. ali-1989 commented on Nov 3, 2025

    @ali-1989

    this bug still exist on flutter 3.35

  13. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 17, 2026
  14. github-actions commented on Oct 9, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Oct 9, 2026
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: text inputEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consolefound in release: 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagesp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions