Repository: flutter
Issue: [Cupertino]: CupertinoTextField with `TextAlign.right` throws `Failed assertion: line 206 pos 12: 'isValid': is not true.`
Labels: a: text input,c: crash,framework,f: cupertino,has reproducible steps,P2,found in release: 3.16,found in release: 3.17,team-text-input,triaged-text-input

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### 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

<details><summary>Code sample</summary>

```dart
CupertinoTextField(
      textAlign: TextAlign.right,
      controller: widget.controller,
    )
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] 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.
```

</details>