flutter_keyboard_visibility icon indicating copy to clipboard operation
flutter_keyboard_visibility copied to clipboard

When open keyboard, automatically closed

Open juanlabrador opened this issue 3 years ago • 24 comments

I receive in console

W/IInputConnectionWrapper(14786): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper(14786): getSelectedText on inactive InputConnection W/IInputConnectionWrapper(14786): getTextAfterCursor on inactive InputConnection W/IInputConnectionWrapper(14786): beginBatchEdit on inactive InputConnection W/IInputConnectionWrapper(14786): endBatchEdit on inactive InputConnection

The keyboard not stay open when open, any idea? If disable o remove the listen, the keyboard stay open.

juanlabrador avatar Sep 08 '20 22:09 juanlabrador

Wow thats interesting. Can you share any code snipped you have, confirm the version of the package, and the device you are using?

MisterJimson avatar Sep 09 '20 00:09 MisterJimson

[✓] Flutter (Channel stable, 1.20.1, on Mac OS X 10.15.6 19G2021, locale es-419)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 11.7) [✓] Android Studio (version 4.0) [✓] IntelliJ IDEA Community Edition (version 2020.2.1) [!] VS Code (version 1.48.0) ✗ Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [✓] Connected device (3 available)

juanlabrador avatar Sep 09 '20 14:09 juanlabrador

The device is a Mi A2 with Android One, Android 10., Is when click on TextFormField, or TextField

juanlabrador avatar Sep 09 '20 14:09 juanlabrador

video-to-gif-converter

juanlabrador avatar Sep 09 '20 14:09 juanlabrador

I use this lib for when keyboard is open, I hide widgets, for the content adjust to write more confortable, when keyboard is hide, I show widgets again

juanlabrador avatar Sep 09 '20 14:09 juanlabrador

Then the method listen, return true when open and immediately false and It close, Thanks.

juanlabrador avatar Sep 09 '20 14:09 juanlabrador

May be related: https://github.com/flutter/flutter/issues/9471

MisterJimson avatar Sep 09 '20 15:09 MisterJimson

I am having this same problem as well, but it didn't seem to persist on iOS, only Android.

tmthecoder avatar Sep 10 '20 00:09 tmthecoder

I would love a reproducible sample to help work on this.

MisterJimson avatar Sep 14 '20 11:09 MisterJimson

I am facing this issue too - on iOS. Have not tried on Android. Keyboard shows up, then disappears VERY quick. Have not been able to track whats causing this.

@MisterJimson here is this issue reproduced: https://github.com/ajaygautam/flutter_repro_keyboard_dismiss_issue

Relevant details have been added to the readme in the repo. I have added you as a collaborator to the repo. Please do feel free to commit changes.

Primary code segments:

class RouteWithKeyboardVisibilityBuilder extends StatelessWidget {
  final String title;

  const RouteWithKeyboardVisibilityBuilder({Key key, this.title = "RouteWithKeyboardVisibilityBuilder"})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return KeyboardVisibilityBuilder(builder: (context, isKeyboardVisible) {
      print("=-=-=-=-=-= Building with keyboard visibility set to: --||$isKeyboardVisible||-- for screen with title $title =-=-=-=-=-=");
      return Material(
          child: Container(
              color: Colors.blue[200],
              child: Center(
                  child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                    Text(title),
                    SizedBox(height: 16),
                    WidgetWithTextEdit(),
                    SizedBox(height: 16),
                    BackNextButtonRow()
                  ]))));
    });
  }
}

class WidgetWithTextEdit extends StatelessWidget {
  final Key key = UniqueKey();

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;

    return SizedBox(
      height: screenSize.height * 0.1,
      width: screenSize.width * 0.67,
      child: new TextFormField(
        key: key,
        decoration: InputDecoration(hintText: "Tap to Enter Data"),
      ),
    );
  }
}

Would appreciate any help / info. Let me know if you want me to try anything.

ajaygautam avatar Dec 23 '20 15:12 ajaygautam

I am having this same problem as well, but it didn't seem to persist on iOS, only Android.

@tmthecoder were you able to resolve this?

ajaygautam avatar Dec 23 '20 15:12 ajaygautam

I am having this same problem as well, but it didn't seem to persist on iOS, only Android.

@tmthecoder were you able to resolve this?

Not yet, I'm still awaiting a resolution

tmthecoder avatar Dec 23 '20 16:12 tmthecoder

So... looks like package keyboard_visibility does not cause this behavior - atleast in the test app at: https://github.com/ajaygautam/flutter_repro_keyboard_dismiss_issue

I have updated the app to support both keyboard_visibility and flutter_keyboard_visibility. In main.dart, look for switchToKeyboardVisibility... is set true... the app will use keyboard_visibility package. If false, the app will use flutter_keyboard_visibility.

Going to try this with my actual app now.

Thanks

ajaygautam avatar Dec 25 '20 13:12 ajaygautam

@ajaygautam can you provide steps to reproduce the issue with your example repo? I am running it and have tried switching switchToKeyboardVisibility false.

I am not seeing any issues. I can clock next and tap in the text field and the keyboard shows correctly.

MisterJimson avatar Jan 05 '21 14:01 MisterJimson

That is strange! It seems to be working fine now. Well... I guess its ok to close this...

FWIW... flutter doctor output:

[✓] Flutter (Channel beta, 1.25.0-8.1.pre, on macOS 11.1 20C69 darwin-arm, locale en-US)
    • Flutter version 1.25.0-8.1.pre at /Users/agautam/tools/flutter
    • Framework revision 8f89f6505b (3 weeks ago), 2020-12-15 15:07:52 -0800
    • Engine revision 92ae191c17
    • Dart version 2.12.0 (build 2.12.0-133.2.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/agautam/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.0

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 4.2 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
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[✓] Android Studio (version 4.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 1.8.0_242-release-1644-b3-6915495)

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

[✓] Connected device (1 available)
    • iPhone (mobile) • 92cc6d36662ed70bd2442ee0aac0decfa2e34e24 • ios • iOS 14.1

• No issues found!

ajaygautam avatar Jan 05 '21 15:01 ajaygautam

Ok. I am going to leave it open as there is still and issue with Android it seems from the other people in this thread.

MisterJimson avatar Jan 05 '21 15:01 MisterJimson

4.0.4-beta.0 is available with a new Android implementation using the fairly new WindowInsetsCompat features.

Any feedback is appreciated before I merge this into a main version. I suspect it may help resolve this issue.

MisterJimson avatar Feb 11 '21 15:02 MisterJimson

Should be closed in 4.0.4, but I had trouble reproducing. Feel free to reopen with more info.

MisterJimson avatar Feb 20 '21 21:02 MisterJimson

Before the flutter 2.0 update arrive this code is working fine but after the flutter 2.0 update and this package update to support null safety, the keyboard now closes when transitioning to a new layout that has 3 columns from only 2 columns

https://user-images.githubusercontent.com/6942408/117092377-b0521f80-ad90-11eb-8c4a-967f24cf4278.mp4

this is the code I used to replicate the problem: https://github.com/haliknihudas666/flutter_keyboardVisibility_demo

please reopen this issue

haliknihudas666 avatar May 05 '21 03:05 haliknihudas666

I have the same issue today (on Android), and i resolve by changing from Stateless Widget to Statefull Widget the Form where the TextInput have the problem

BrunoC96 avatar Aug 01 '21 15:08 BrunoC96

Thanks @BrunoC96 for the help, it worked 🎉. But dont know why this behavior for the Stateless widget.

Kishan-Somaiya avatar Aug 25 '21 13:08 Kishan-Somaiya

Unfortunately does not work for me. Tried all workaround until this message.

[✓] Flutter (Channel stable, 3.3.9, on macOS 12.3.1 21E258 darwin-arm, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[!] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.4)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

xetra11 avatar Dec 13 '22 12:12 xetra11

Hi there, I had the same issue and I was able to fix it by creating a GlobalKey<FormState> and using that key with the TextField.

This StackOverflow post has the details: https://stackoverflow.com/questions/51320692/flutter-keyboard-disappears-immediately-when-editing-my-text-fields

maxstubbersfield avatar May 12 '23 07:05 maxstubbersfield

I have the exact same problem. When keyboard is shown I remove a big widget from the widget tree, that causes the keyboard to be dismissed.

Edit: I found an workaround. If I add a GlobalKey to my TextField the keyboard no longer dismisses.

tudor07 avatar Aug 14 '23 13:08 tudor07