flutter / flutter/flutter

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

Open
#144,463 15 comments 5 reactions 1 assignee Claimed by @okorohelijah View on GitHub
:hourglass_flowing_sand: a: text input engine found in release: 3.19 found in release: 3.20 framework fyi-text-input has reproducible steps P2 platform-ios team-ios triaged-ios
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### 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

```dart
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 createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
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

https://github.com/flutter/flutter/assets/6888015/d2470686-152c-4f3b-8476-66763d7a7932

### Logs

Logs

```console
no logs
```

### Flutter Doctor output

Doctor output

```console
[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.

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.