Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapsing the software keyboard doesn't lose the focus from textfield in 3.22.0, while it worked in 3.19.6 #148527

Open
wuweijian1997 opened this issue May 17, 2024 · 15 comments
Labels
a: text input Entering text in a text field or keyboard related problems c: regression It was better in the past than it is now f: focus Focus traversal, gaining or losing focus found in release: 3.22 Found to occur in 3.22 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P3 Issues that are less important to the Flutter project team-text-input Owned by Text Input team triaged-text-input Triaged by Text Input team

Comments

@wuweijian1997
Copy link

wuweijian1997 commented May 17, 2024

Steps to reproduce

This issue does not exist in Flutter 3.19.3, it only occurs in Flutter 3.22.0

  1. focus TextField
  2. Collapse the keyboard
  3. FocusScope.of(context).requestFocus(smsInput);

This issue does not exist in Flutter 3.19.3, it only occurs in Flutter 3.22.0

Expected results

TextField refocus

Actual results

refocus not work

FocusScope.of(context).requestFocus(smsInput); /// not work

Code sample

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

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

  @override
  State<TextFieldFocusDemo> createState() => _TextFieldFocusDemoState();
}

class _TextFieldFocusDemoState extends State<TextFieldFocusDemo> {
  late FocusNode smsInput;
  @override
  void initState() {
    smsInput = FocusNode();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: TextField(
          focusNode: smsInput,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add),
        onPressed: () {
          FocusScope.of(context).requestFocus(smsInput);

        },
      ),
    );
  }
  @override
  void dispose() {
    smsInput.dispose();
    super.dispose();
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [版本 10.0.19044.1586], locale zh-CN)
    • Flutter version 3.22.0 on channel stable at D:\env\flutter\flutter-3.22.0
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5dcb86f68f (8 days ago), 2024-05-09 07:39:20 -0500
    • Engine revision f6344b75dc
    • Dart version 3.4.0
    • DevTools version 2.34.3
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\Administrator\AppData\Local\Android\Sdk
    • Platform android-VanillaIceCream, build-tools 34.0.0
    • ANDROID_HOME = C:\Users\Administrator\AppData\Local\Android\Sdk
    • Java binary at: D:\AndroidStudio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
    • All Android licenses accepted.

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

[X] Visual Studio - develop Windows apps
    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 2023.2)
    • Android Studio at D:\AndroidStudio
    • 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
    • android-studio-dir = D:\AndroidStudio
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)

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

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [版本 10.0.19044.1586]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 124.0.6367.158
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 124.0.2478.105

[√] Network resources
    • All expected network resources are available.
@YimZungWo

This comment was marked as duplicate.

@sendiagustian
Copy link

In my case set keyboardType = KeyboardType.number, and when req focus call blink type text.

ScreenRecord_2024_05_17_11_36_55.mp4

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 17, 2024
@darshankawar
Copy link
Member

@wuweijian1997
I tried on stable 3.22.0 and was not able to replicate. After tapping on FAB, the textfield gets and focus and shows the active cursor as shown in video below:

148527.mov

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@wuweijian1997
Copy link
Author

@wuweijian1997 I tried on stable 3.22.0 and was not able to replicate. After tapping on FAB, the textfield gets and focus and shows the active cursor as shown in video below:

148527.mov

image

click this to Collapse the keyboard.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@wuweijian1997
Copy link
Author

@darshankawar try click here.then try to focus the TextField
image

@darshankawar
Copy link
Member

Tried the same but still couldn't replicate.

148527_1.mov

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@Bestfootballer
Copy link

Bestfootballer commented May 17, 2024

@wuweijian1997 Hi, I tried to reproduce the bug by following the order of the steps you wrote, but everything works fine for me too.

Registrazione.schermo.2024-05-17.alle.12.30.33.mov

@wuweijian1997
Copy link
Author

@darshankawar @Bestfootballer

FocusScope.of(context).requestFocus(smsInput); /// not work
flutter --version
Flutter 3.22.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5dcb86f68f (8 days ago) • 2024-05-09 07:39:20 -0500
Engine • revision f6344b75dc
Tools • Dart 3.4.0 • DevTools 2.34.3

Android.Emulator.-.Pixel_6_Pro_API_33_5554.2024-05-17.19-58-25.mp4

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2024
@wuweijian1997
Copy link
Author

Tried the same but still couldn't replicate.

148527_1.mov

click fab TextField not focus,you replicate it.

@Bestfootballer
Copy link

Bestfootballer commented May 17, 2024

@wuweijian1997 I'm sorry, but I thought I had installed the latest version of Flutter when I did the test.
Anyway, I upgraded Flutter to latest version (3.22) and now the focus didn't work for me too.

Registrazione.schermo.2024-05-17.alle.14.38.55.mov

So @darshankawar , I confirm that this instruction isn't working:

FocusScope.of(context).requestFocus(smsInput);

flutter --version
Flutter 3.22.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5dcb86f68f (8 days ago) • 2024-05-09 07:39:20 -0500
Engine • revision f6344b75dc
Tools • Dart 3.4.0 • DevTools 2.34.3

@darshankawar
Copy link
Member

@wuweijian1997 What's the expected behavior after tapping FAB ? Can you also show a video of it working in previous version ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 20, 2024
@wuweijian1997

This comment was marked as off-topic.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 20, 2024
@darshankawar darshankawar changed the title TextField can't focus in android (This issue does not exist in Flutter 3.19.3, it only occurs in Flutter 3.22.0) Collapsing the software keyboard doesn't lose the focus from textfield in 3.22.0, while it worked in 3.19.6 May 20, 2024
@darshankawar
Copy link
Member

@wuweijian1997 I was trying to understand the behavior that exists in previous version against the one which isn't working in latest. Please read the github code of conduct while commenting.

Coming back to the issue, I checked in stable 3.19.6 wherein the behavior is as below:

148527.mov

ie, tapping the collapse button also loses the focus from the textfield as shown, but in latest version, the focus remains in the textfield.

stable, master flutter doctor -v
[!] Flutter (Channel stable, 3.22.0, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.22.0 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5dcb86f68f (5 days ago), 2024-05-09 07:39:20 -0500
    • Engine revision f6344b75dc
    • Dart version 3.4.0
    • DevTools version 2.34.3
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

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

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.22.0-35.0.pre.24, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 3.22.0-35.0.pre.24 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2b0d879ec7 (63 minutes ago), 2024-05-16 00:13:26 -0400
    • Engine revision 942d7c35de
    • Dart version 3.5.0 (build 3.5.0-160.0.dev)
    • DevTools version 2.36.0-dev.10
    • 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 30.0.3)
    • Android SDK at /Users/dhs/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13C100
    • CocoaPods version 1.11.2

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

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 65.1.4
    • Dart plugin version 213.7228

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

[✓] Connected device (3 available)
    • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
      • iOS 15.3.1 19D52
    • macOS (desktop)           • macos                                    •
      darwin-x64     • macOS 12.2.1 21D62 darwin-x64
    • Chrome (web)              • chrome                                   •
      web-javascript • Google Chrome 109.0.5414.119

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

! Doctor found issues in 1 category.
      
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

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

! Doctor found issues in 1 category.



@darshankawar darshankawar added a: text input Entering text in a text field or keyboard related problems has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.22 Found to occur in 3.22 c: regression It was better in the past than it is now team-text-input Owned by Text Input team framework flutter/packages/flutter repository. See also f: labels. f: focus Focus traversal, gaining or losing focus and removed in triage Presently being triaged by the triage team labels May 20, 2024
@justinmc
Copy link
Contributor

@wuweijian1997 Is the behavior seen in the previous comment what you are expecting?

@justinmc justinmc added P3 Issues that are less important to the Flutter project triaged-text-input Triaged by Text Input team labels May 23, 2024
@wuweijian1997
Copy link
Author

@justinmc I expect the keyboard to be raised when running the code

FocusScope.of(context).requestFocus(smsInput);

But in 3.22.0, this doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems c: regression It was better in the past than it is now f: focus Focus traversal, gaining or losing focus found in release: 3.22 Found to occur in 3.22 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P3 Issues that are less important to the Flutter project team-text-input Owned by Text Input team triaged-text-input Triaged by Text Input team
Projects
None yet
Development

No branches or pull requests

6 participants