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

How to pin keyboard when Popupmenu appears #24843

Open
zywj opened this issue Nov 29, 2018 · 14 comments
Open

How to pin keyboard when Popupmenu appears #24843

zywj opened this issue Nov 29, 2018 · 14 comments
Labels
a: text input Entering text in a text field or keyboard related problems c: new feature Nothing broken; request for a new capability customer: crowd Affects or could affect many people, though not necessarily a specific customer. f: material design flutter/packages/flutter/material repository. found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@zywj
Copy link

zywj commented Nov 29, 2018

How can I hold the keyboard when click PopupMenuButton.
I have noticed that why the keyboard will disappear is PopupMenu using Navigation.push
So, is there a workaournd to implement my require?

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 150.0,
              child: TextField(
                autofocus: false,
                decoration: new InputDecoration(
                  hintStyle:
                      TextStyle(color: const Color(0xFFAAAAAA), fontSize: 15.0),
                  border: OutlineInputBorder(),
                ),
              ),
            ),
            PopupMenuButton<String>(
              onSelected: (String r) {},
              itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
                    const PopupMenuItem<String>(
                      value: "text",
                      child: const Text('Popup'),
                    ),
                  ],
            ),
          ],
        ),
      ),
    );
  }

Here is the flutter doctor -v

[✓] Flutter (Channel beta, v0.10.2, on Mac OS X 10.14.1 18B75, locale en-HK)
    • Flutter version 0.10.2 at /usr/local/flutter
    • Framework revision d8cbb80206 (5 weeks ago), 2018-10-26 01:30:21 -0400
    • Engine revision 6c2ade9fa2
    • Dart version 2.1.0-dev.8.0.flutter-bf26f760b1

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit https://flutter.io/setup/#android-setup for detailed
      instructions).
      If Android SDK has been installed to a custom location, set $ANDROID_HOME
      to that location.
      You may also want to add it to your PATH environment variable.


[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.io/setup/#android-setup for detailed
      instructions).

[✓] IntelliJ IDEA Community Edition (version 2018.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 30.0.2
    • Dart plugin version 182.5124

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

[✓] Connected device (1 available)
    • iPhone 7 • 463B2CA4-5966-4EC8-B0BE-6A174EA45B7B • ios • iOS 12.1
      (simulator)

! Doctor found issues in 2 categories.
@zywj zywj changed the title How to hold keyboard when Popupmenu appears How to pin keyboard when Popupmenu appears Nov 29, 2018
@zoechi zoechi added a: text input Entering text in a text field or keyboard related problems c: new feature Nothing broken; request for a new capability labels Nov 29, 2018
@zoechi zoechi added this to the Stretch Goals milestone Nov 29, 2018
@zoechi zoechi added the framework flutter/packages/flutter repository. See also f: labels. label Dec 13, 2018
@goderbauer goderbauer added the f: material design flutter/packages/flutter/material repository. label Jan 4, 2019
@hiroshihorie
Copy link

This is bugging me also...

@Hixie Hixie modified the milestones: Stretch Goals, Goals Jan 7, 2020
@Hixie
Copy link
Contributor

Hixie commented Jan 7, 2020

cc @gspencergoog

@edwin-alvarez
Copy link

any workaround for this issue?

@edwin-alvarez
Copy link

edwin-alvarez commented May 28, 2020

Note: this is only a workaround since I'm using a delay for 200 milliseconds, but I noticed that's good enough time to allow redraw.

Widget offsetPopup2() {
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
WidgetsBinding.instance.addPostFrameCallback((
) async {
await Future.delayed(Duration(milliseconds: 200));
RenderBox box = _more_o.currentContext.findRenderObject();
Offset position = box.localToGlobal(Offset.zero); //this is global position
double y = position.dy; //this is y - I think it's what you want

            _showMenu(position);
        });

      },
      child: Icon(Icons.more_horiz, key: _more_o,)
);

}

_showMenu(Offset offset) async {
double left = offset.dx;
double top = offset.dy;
await showMenu(
context: context,
position: RelativeRect.fromLTRB(left, top, 0, 0),
items: [
PopupMenuItem(
value: 1,
child: Text(
'Bible Study'.i18n,
style: TextStyle(color: Colors.black),
),
),
PopupMenuItem(
value: 2,
child: Text(
'Return Visit'.i18n,
style: TextStyle(color: Colors.black),
),
),
],
elevation: 8.0,
);
}

some other links which could be useful
//https://stackoverflow.com/questions/43349013/how-to-open-a-popupmenubutton
//https://stackoverflow.com/questions/54291245/get-y-position-of-container-on-flutter

@kf6gpe kf6gpe added the P2 Important issues not at the top of the work list label May 29, 2020
@Hixie Hixie removed this from the None. milestone Aug 17, 2020
@Vitor-Bukovitz
Copy link

@zoechi any update to this issue?

@pabloserranof
Copy link

Any progress with this?

@PegasisForever
Copy link

I create a package keep_keyboard_popup_menu to solve this issue:

@Vitor-Bukovitz
Copy link

This is the workaround I used:

  final _menuKey = GlobalKey<PopupMenuButtonState>();

  Widget _uploadButton() {
    return Listener(
      onPointerDown: (_) async {
        if (FocusScope.of(context).hasFocus) {
          FocusScope.of(context).unfocus();
          await Future.delayed(Duration(milliseconds: 400));
        }
        _menuKey.currentState.showButtonMenu();
      },
      child: PopupMenuButton(
        key: _menuKey,
        enabled: false,
        icon: Icon(
          Icons.add_circle_outline,
          color: Colors.black,
        ),
        offset: Offset(0, -120),
        onSelected: (value) async {},
        itemBuilder: (context) {
          return [
            PopupMenuItem(
              value: 'camera',
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(
                    Icons.camera_alt,
                    color: Theme.of(context).accentColor,
                  ),
                  Text(' Take a photo')
                ],
              ),
            ),
          ];
        },
      ),
    );
  }

Obs: The parent widget must be a stateful

@jangruenwaldt
Copy link

Pleaseeeee fix this! This is quite annoying

@NaikSoftware
Copy link

We really need way to show widgets over keyboard as Android AlertDialog, etc.

@kbanta11
Copy link

kbanta11 commented Sep 2, 2021

Any update on this? Not able to get either of the workarounds to work consistently, so my popupmenu ends up in the middle of the page if the keyboard is open

@SalishKumar
Copy link

any update??? stuck on same problem

@darshankawar darshankawar added the customer: crowd Affects or could affect many people, though not necessarily a specific customer. label Sep 29, 2021
@darshankawar
Copy link
Member

This behavior still occurs using latest stable (2.5.1) and master version, as, a new issue was opened to report it.

Added a crowd label after looking at comments in this thread.

/cc: @gspencergoog for further insights on this issue.

@darshankawar darshankawar added found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on labels Sep 29, 2021
@ivanchaukn
Copy link

ivanchaukn commented Dec 18, 2022

Can't believe this problem is still not solve until now...

@darshankawar do you know whether there are any solution for this issue after a year?

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-design Owned by Design Languages team triaged-design Triaged by Design Languages team labels Jul 8, 2023
@gnprice gnprice added team-framework Owned by Framework team triaged-framework Triaged by Framework team and removed team-design Owned by Design Languages team triaged-design Triaged by Design Languages team labels Jul 18, 2023
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: new feature Nothing broken; request for a new capability customer: crowd Affects or could affect many people, though not necessarily a specific customer. f: material design flutter/packages/flutter/material repository. found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests