Skip to content

Text field cursor position in RTL goes to the penultimate character #107006

@M144-Coder

Description

@M144-Coder

When the user writes then taps at the end of a text field in RTL app the cursor position is set to the penultimate character instead of the last one. This issue occurs on both Android (tested on multiple devices from different vendors and emulator) and iOS.

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Write Arabic or any other RTL language in the text field.
  3. Tap on any place to change the cursor position then tap again at the end of the text field, the cursor position will change to the penultimate character.

Expected results:
The cursor position should be after the last character.

Actual results:
The cursor position moves to the penultimate character.

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      locale: const Locale("ar"),
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [Locale("ar")],
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: const Center(
        child: Padding(
          padding: EdgeInsets.all(16),
          child: TextField(),
        ),
      ),
    );
  }
}

Logs
Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 4,352ms.
D/InputConnectionAdaptor( 3905): The input method toggled cursor monitoring on
D/EGL_emulation( 3905): eglMakeCurrent: 0xb1529440: ver 2 0 (tinfo 0x96884cd0)
W/IInputConnectionWrapper( 3905): reportFullscreenMode on inexistent InputConnection
W/IInputConnectionWrapper( 3905): finishComposingText on inactive InputConnection
D/EGL_emulation( 3905): eglMakeCurrent: 0xa5d2dc40: ver 2 0 (tinfo 0x96884430)
D/EGL_emulation( 3905): eglMakeCurrent: 0xa5d2dc40: ver 2 0 (tinfo 0x96884430)
D/EGL_emulation( 3905): eglMakeCurrent: 0xb1529440: ver 2 0 (tinfo 0x96884cd0)
D/InputConnectionAdaptor( 3905): The input method toggled cursor monitoring on
I/TextInputPlugin( 3905): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 3905): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 3905): getTextBeforeCursor on inactive InputConnection
D/InputConnectionAdaptor( 3905): The input method toggled cursor monitoring on
Analyzing test_app...
No issues found! (ran in 8.6s)
[✓] Flutter (Channel stable, 3.0.3, on Microsoft Windows [Version 10.0.19044.1766], locale en-US)
    • Flutter version 3.0.3 at E:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 676cefaaff (10 days ago), 2022-06-22 11:34:49 -0700
    • Engine revision ffe7b86a1e
    • Dart version 2.17.5
    • DevTools version 2.12.2

Checking Android licenses is taking an unexpectedly long time...[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at E:\Android_SDK\android-sdk-windows
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = E:\Android_SDK\android-sdk-windows
    • ANDROID_SDK_ROOT = E:\Android_SDK\android-sdk-windows
    • Java binary at: E:\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Users\MyPc\AppData\Local\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.0 Preview 1.0)
    • Visual Studio at E:\Program Files\Microsoft Visual Studio\2022\Preview
    • Visual Studio Community 2022 version 17.3.32505.426
    • The current Visual Studio installation is a pre-release version. It may not be supported by Flutter yet.
    • Windows 10 SDK version 10.0.18362.0
    ✗ Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and
      include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK

[✓] Android Studio (version 2021.2)
    • Android Studio at E:\android-studio
    • 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.12+7-b1504.28-7817840)

[✓] VS Code (version 1.68.1)
    • VS Code at C:\Users\MyPc\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.42.0

[✓] Connected device (4 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 7.0 (API 24) (emulator)
    • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Version 10.0.19044.1766]
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 102.0.5005.115
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 101.0.1210.53

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

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions