Skip to content

[iOS] text field loses focus after Look Up text selection #144463

Closed

Description

@starikovvm

Steps to reproduce

App is launched on iOS 17.2 (reproduces both on a simulator and on a real device)

  1. Select text in Text Field
  2. Press Look up
  3. Close the Look up dialog

Expected results

Keyboard hides or text field returns its focus

Actual results

Keyboard persists on screen, but the text field does not retain focus and keyboard does not hide via unfocus() (see video)

Code sample

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

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

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

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const TextField(),
            TextButton(
              onPressed: () => FocusScope.of(context).unfocus(),
              child: const Text('FocusScope.of(context).unfocus()'),
            ),
            TextButton(
              onPressed: () => FocusManager.instance.primaryFocus?.unfocus(),
              child:
                  const Text('FocusManager.instance.primaryFocus?.unfocus()'),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
Screenshot.2024-03-01.at.14.11.27.mp4

Logs

Logs
no logs

Flutter Doctor output

Doctor output
[flutter] flutter doctor -v
[!] Flutter (Channel stable, 3.19.2, on macOS 14.3.1 23D60 darwin-arm64, locale ru-RU)
    • Flutter version 3.19.2 on channel stable at /Users/viktorstarikov/fvm/versions/3.19.2
    ! Warning: `flutter` on your path resolves to /Users/viktorstarikov/fvm/versions/3.10.4/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/viktorstarikov/fvm/versions/3.19.2. Consider adding /Users/viktorstarikov/fvm/versions/3.19.2/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.0.1/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/viktorstarikov/fvm/versions/3.19.2. Consider adding /Users/viktorstarikov/fvm/versions/3.19.2/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7482962148 (2 days ago), 2024-02-27 16:51:22 -0500
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1
    • 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 33.0.2)
    • Android SDK at /Users/viktorstarikov/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode-15.2.0.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.86.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.82.0

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 13 (API 33) (emulator)
    • iPhone 6s Plus (mobile)     • 00008110-000A388A3AF9801E            • ios            • iOS 17.2.1 21C66
    • iPhone 15 Pro Max (mobile)  • 97CAF3A4-246E-462F-968B-A414DE0A3445 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 122.0.6261.94
    ! Error: Browsing on the local area network for Apple Watch — Viktor. Ensure the device is unlocked and discoverable via Bluetooth. (code -27)

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. danagbemava-nc commented on Mar 1, 2024

    @danagbemava-nc
    Member

    Reproducible using the code sample provided above.

    With the native iOS notes and reminders app, the behaviours are different. Notes dismisses the keyboard whereas reminders refocuses the keyboard. See the recordings below

    It looks like the lookUpSelection method in the framework doesn't handle anything else after calling the method to invoke the look up window.

    Future<void> lookUpSelection(SelectionChangedCause cause) async {
    assert(!widget.obscureText);
    final String text = textEditingValue.selection.textInside(textEditingValue.text);
    if (widget.obscureText || text.isEmpty) {
    return;
    }
    await SystemChannels.platform.invokeMethod(
    'LookUp.invoke',
    text,
    );
    }

    flutter notes reminder
    RPReplay_Final1709287250.MP4
    RPReplay_Final1709287076.MP4
    RPReplay_Final1709285659.MP4
    flutter doctor -v
    [✓] Flutter (Channel stable, 3.19.2, on macOS 14.3.1 23D60 darwin-arm64, locale en-GB)
        • Flutter version 3.19.2 on channel stable at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 7482962148 (3 days ago), 2024-02-27 16:51:22 -0500
        • Engine revision 04817c99c9
        • Dart version 3.3.0
        • DevTools version 2.31.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.2)
        • Xcode at /Applications/Xcode-15.2.0.app/Contents/Developer
        • Build 15C500b
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.1)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • 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 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.86.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.82.0
    
    [✓] Connected device (4 available)
        • Nexus (mobile)       • 00008020-001875E83A38002E • ios            • iOS 17.3.1 21D61
        • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios            • iOS 17.3.1 21D61
        • macOS (desktop)      • macos                     • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
        • Chrome (web)         • chrome                    • web-javascript • Google Chrome 122.0.6261.69
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.20.0-16.0.pre.43, on macOS 14.3.1 23D60 darwin-arm64, locale en-GB)
        • Flutter version 3.20.0-16.0.pre.43 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision ab10e2b1dd (5 hours ago), 2024-03-01 00:21:09 -0500
        • Engine revision f68cc57cbe
        • Dart version 3.4.0 (build 3.4.0-190.0.dev)
        • DevTools version 2.33.1
        • 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 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.2)
        • Xcode at /Applications/Xcode-15.2.0.app/Contents/Developer
        • Build 15C500b
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.1)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • 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 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.86.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.82.0
    
    [✓] Connected device (5 available)
        • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.3.1 21D61
        • Dean’s iPad (mobile)            • 00008103-000825C811E3401E • ios            • iOS 17.3.1 21D61
        • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
        • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 14.3.1 23D60 darwin-arm64
        • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 122.0.6261.69
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    
  2. added
    a: text inputEntering text in a text field or keyboard related problems
    platform-iosiOS applications specifically
    frameworkflutter/packages/flutter repository. See also f: labels.
    engineflutter/engine related. See also e: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-iosOwned by iOS platform team
    and removed
    in triagePresently being triaged by the triage team
    on Mar 1, 2024
  3. hellohuanlin commented on Mar 5, 2024

    @hellohuanlin
    Contributor

    can take a look if it's possible to track what was on focus before presenting the lookup window, and then regain the focus after look up window is dismissed (not sure if there's a delegate callback we can use when look up window is dismissed)

    cc @LouiseHsu

  4. self-assigned this
    on Mar 6, 2024
  5. added
    P2Important issues not at the top of the work list
    on Mar 6, 2024
  6. 22 remaining items

  7. Renzo-Olivares commented on Aug 28, 2025

    @Renzo-Olivares
    Contributor

    From triage: maybe this is related to shake to undo causing the TextField possibly to lose focus and not process the undo action #150522.

  8. LongCatIsLooong commented on Aug 28, 2025

    @LongCatIsLooong
    Contributor

    From triage: maybe this is related to shake to undo causing the TextField possibly to lose focus and not process the undo action #150522.

    The native text field must not close the input connection in these cases so it can receive undo commands even after losing focus.

  9. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Jan 2, 2026
  10. flutter-triage-bot commented on Jan 2, 2026

    @flutter-triage-bot

    This issue is assigned to @okorohelijah but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  11. okorohelijah commented on Mar 16, 2026

    @okorohelijah
    Contributor

    Added a comment in #173846 (comment)

  12. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Mar 16, 2026
  13. flutter-triage-bot commented on Jul 21, 2026

    @flutter-triage-bot

    This issue is assigned to @okorohelijah but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  14. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Jul 21, 2026
  15. LongCatIsLooong commented on Sep 24, 2026

    @LongCatIsLooong
    Contributor

    I think #191781 fixes this.

  16. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Sep 25, 2026
  17. github-actions commented on Nov 4, 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.

  18. locked as resolved and limited conversation to collaborators on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.found in release: 3.19Found to occur in 3.19found in release: 3.20Found to occur in 3.20frameworkflutter/packages/flutter repository. See also f: labels.fyi-text-inputFor the attention of Text Input teamhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions