Repository navigation
Whether focus exists has nothing to do with whether the keyboard is open #140508
Copy link
Copy link
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.f: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18Found to occur in 3.18frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Steps to reproduce
Related issues:
Related Pull Requests:
flutter-team-archive/engine#41500
#123929
There should be no correlation between whether the keyboard is open and whether focus exists. Should keep focus after keyboard was closed.
related comments:
flutter-team-archive/engine#41500 (comment)
flutter-team-archive/engine#40746 (comment)
Expected results
Keep focus when keyboard was closed.
before.fix.mp4
Actual results
the focus is gone after the keyboard is closed
after.fix.mp4
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(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
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: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[TextField()],
),
),
);
}
}Flutter Doctor output
Doctor
[!] Flutter (Channel [user-branch], 3.18.0-14.0.pre.46, on macOS 14.2.1 23C71
darwin-arm64, locale zh-Hans-CN)
! Flutter version 3.18.0-14.0.pre.46 on channel [user-branch] at
/Users/yangjiakang/flutter/framework
Currently on an unknown channel. Run `flutter channel` to switch to an
official channel.
If that doesn't fix the issue, reinstall Flutter by following instructions
at https://flutter.dev/docs/get-started/install.
! Upstream repository unknown source is not a standard remote.
Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss
this error.
• Framework revision d746007fcd (12 小时前), 2023-12-20 16:19:59 -0800
• Engine revision c70f0a495a
• Dart version 3.3.0 (build 3.3.0-244.0.dev)
• DevTools version 2.31.0-dev.0
• 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/yangjiakang/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/yangjiakang/Library/Android/sdk
• Java binary at: /Applications/Android
Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 15.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C65
! CocoaPods 1.11.3 out of date (1.13.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade see
https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
for instructions.
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• 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.6+0-17.0.6b829.9-10027231)
[!] Android Studio (version unknown)
• Android Studio at
/Users/yangjiakang/Code/androidx/studio/android-studio-2023.1.1.15-mac_arm
/Android Studio Preview.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
✗ Unable to determine Android Studio version.
• Java version OpenJDK Runtime Environment (build
17.0.7+0-17.0.7b1000.6-10550314)
[!] Android Studio (version unknown)
• Android Studio at
/Users/yangjiakang/Code/aosp/frameworks/support/studio/android-studio-2023
.2.1.4-mac_arm/Android Studio Preview.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
✗ Unable to determine Android Studio version.
• Java version OpenJDK Runtime Environment (build
17.0.8+0-17.0.8b1000.22-10799086)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.2)
• IntelliJ at /Applications/IntelliJ IDEA.app
• 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
[✓] VS Code (version 1.85.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.78.0
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 4 categories.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.f: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18Found to occur in 3.18frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
[-]Keyboard behavior is inconsistent with system default[/-][+]Whether focus exists has nothing to do with whether the keyboard is open[/+]OPTRONIX-10 commentedon Dec 21, 2023
can you please be more clear that weather you want focus after closing keyboard or not?
CoderBuck commentedon Dec 21, 2023
Indeed, in native Android applications, the focus remains unaffected when the keyboard is dismissed. Flutter should ideally exhibit similar behavior, or at least it used to behave that way in the past.
To be honest, this seems to be a breaking change. When our app upgraded to Flutter 3.16, this change led to some bugs. In order to revert to the behavior prior to the upgrade, we had to hook into the TextInputChannel.
MeandNi commentedon Dec 21, 2023
I want focus when keyboard was closed.
DBOutlink commentedon Dec 21, 2023
Could you show me how to use this extension on your android code? I have the same issue...
CoderBuck commentedon Dec 22, 2023
@DBOutlink
dam-ease commentedon Dec 22, 2023
Thanks for filing this @MeandNi.
I can reproduce this on the latest
stableandmasterchannel.I see this seems to be a known issue and is similar/related to #31985, can you please check this out?
MeandNi commentedon Dec 22, 2023
@dam-ease
From what I have observed, flutter-team-archive/engine#41500, #123929 These two PRs have met my needs after rolling back. I hope that the focus can be retained after I close the keyboard. #31985 is probably a more ideal situation.
4 remaining items
Revert "Close connection on keyboard close (#41500)" (#49366)
MeandNi commentedon Feb 4, 2024
flutter-team-archive/engine#49366 has been merged. Shouldn’t iOS also have this default behavior? #123523 @camsim99 @mossmana
auradigitaldev commentedon Jul 16, 2024
Question - am I missing something or does this make it impossible to make the keyboard reappear? I had a page that relied on the fact that dismissing the keyboard also removed focus, and I would call "requestFocus()" to show the keyboard. Now it doesn't seem possible to programmatically show the keyboard, though I'd love to be proved wrong with a workaround!
In other words, is it possible to replicate the previous functionality where the keyboard dismissal is linked to focus? It's really important for one of the flows in my app.
bleroux commentedon Jul 16, 2024
You can make the keyboard reappear using:
auradigitaldev commentedon Jul 17, 2024
Ohhh perfect, I was missing that - thanks so much!
Revert "Close connection on keyboard close (#41500)" (flutter-team-ar…
Search bar keeps the keyboard when it switches language