MisterJimson / flutter_keyboard_visibility

Get notified on keyboard visibility changes in your Flutter app
MIT License
408 stars 122 forks source link

When open keyboard, automatically closed #37

Open juanlabrador opened 4 years ago

juanlabrador commented 4 years ago

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.

MisterJimson commented 4 years ago

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

juanlabrador commented 4 years ago

[✓] 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 commented 4 years ago

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

juanlabrador commented 4 years ago

video-to-gif-converter

juanlabrador commented 4 years ago

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 commented 4 years ago

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

MisterJimson commented 4 years ago

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

tmthecoder commented 4 years ago

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

MisterJimson commented 4 years ago

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

ajaygautam commented 3 years ago

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 commented 3 years ago

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?

tmthecoder commented 3 years ago

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

ajaygautam commented 3 years ago

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

MisterJimson commented 3 years ago

@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.

ajaygautam commented 3 years ago

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!
MisterJimson commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

haliknihudas666 commented 3 years ago

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

BrunoC96 commented 3 years ago

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

Kishan-Somaiya commented 3 years ago

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

xetra11 commented 1 year ago

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
maxstubbersfield commented 1 year ago

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

tudor07 commented 1 year ago

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.