Skip to content

The auto correction incorrectly highlights the text entered in TextField on iOS devices running on mobile browser. #168322

@alexn777

Description

@alexn777

Steps to reproduce

  1. Create a Flutter Web project
  2. Add TextField
  3. Load the application on iOS device with auto correction turned on
  4. Start typing the text

Expected results

The auto correction correctly highlights the text.

Actual results

The auto correction incorrectly highlights the text. We noticed this issue on iPhone X, iPhone 13 mini and iPhone 16.

Code sample

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Text Field Test',
      home: Scaffold(
        body: HomeScreen(),
      ),
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  HomeScreenState createState() => HomeScreenState();
}

class HomeScreenState extends State<HomeScreen> {
  late final TextEditingController _textFieldController;
  late bool _isAutoCorrectionOn;

  @override
  void initState() {
    super.initState();

    _textFieldController = TextEditingController();
    _isAutoCorrectionOn = true;
  }

  @override
  void dispose() {
    _textFieldController.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    InputDecoration inputDecoration = InputDecoration(
      labelText: 'Type a text',
      hintText: 'Type a text',
      floatingLabelBehavior: FloatingLabelBehavior.never,
      contentPadding: const EdgeInsets.all(16),
      enabledBorder: OutlineInputBorder(
        borderRadius: BorderRadius.circular(24),
        borderSide: const BorderSide(
          width: 1,
          color: Color.fromRGBO(0, 0, 0, 0.05),
        ),
      ),
      focusedBorder: OutlineInputBorder(
        borderRadius: BorderRadius.circular(24),
        borderSide: const BorderSide(
          width: 1,
          color: Color.fromRGBO(127, 202, 222, 1),
        ),
      ),
    );

    return SingleChildScrollView(
      padding: EdgeInsets.all(20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Text('Auto correction'),
              Checkbox(
                value: _isAutoCorrectionOn,
                onChanged: (value) {
                  setState(() {
                    _isAutoCorrectionOn = value ?? true;
                  });
                },
              ),
            ],
          ),
          SizedBox(height: 50),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('Text field value:'),
              SizedBox(width: 10),
              Expanded(
                child: Text(_textFieldController.text)
              ),
            ],
          ),
          SizedBox(height: 10),
          TextField(
            controller: _textFieldController,
            autocorrect: _isAutoCorrectionOn,
            maxLength: 200,
            minLines: 1,
            maxLines: 5,
            buildCounter: (
              BuildContext context, {
                int? currentLength,
                int? maxLength,
                bool? isFocused
              }
            ) => null,
            keyboardType: TextInputType.text,
            decoration: inputDecoration,
            onChanged: (value) {
              setState(() {
              });
            },
          ),
          SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              setState(() {
                _textFieldController.text = '';
              });
            },
            child: Text('Clear'),
          ),
        ],
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
TextField.issues.mp4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [Version 10.0.19045.2965], locale ru-RU) [499ms]
    • Flutter version 3.29.3 on channel stable at C:\SDK\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ea121f8859 (3 weeks ago), 2025-04-11 19:10:07 +0000
    • Engine revision cf56914b32
    • Dart version 3.7.2
    • DevTools version 2.42.3

[√] Windows Version (10 Pro 64-bit, 22H2, 2009) [1 161ms]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [3,2s]
    • Android SDK at C:\Users\alexn\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13355223-b631.42)
    • All Android licenses accepted.

[√] Chrome - develop for the web [27ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps [26ms]
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2024.3) [23ms]
    • Android Studio at C:\Program Files\Android\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 21.0.6+-13355223-b631.42)

[√] VS Code (version 1.99.3) [21ms]
    • VS Code at C:\Users\alexn\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available) [216ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.2965]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 135.0.7049.116
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 135.0.3179.73

[√] Network resources [1 357ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

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 problemsfound in release: 3.29Found to occur in 3.29found in release: 3.32Found to occur in 3.32has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyplatform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions