flutter_typeahead icon indicating copy to clipboard operation
flutter_typeahead copied to clipboard

onSuggestionSelected not called in Web

Open afratul-taohid opened this issue 4 years ago • 10 comments

i tried both flutter_typeahead_web and flutter_typeahead. but onSuggestionSelected not called in web..

afratul-taohid avatar May 10 '20 15:05 afratul-taohid

I also have encountered this, much to my dismay, it also seems to not select in sync with the mouse.

Going to use GestureDetector with Overlay instead I think.

shadowdogg avatar May 26 '20 14:05 shadowdogg

Hello did you solve this problem? @shadowdogg could you please tell us if GestureDetector with Overlay solved this issue? if yes a simple showcase is very appreciated

bytejutsu avatar Jun 01 '20 04:06 bytejutsu

@DhiaEddineNabli it does work, but i'm struggling with the logic regarding opening and closing of the overlay, as for me, change of focus does not perform correctly. I followed: https://medium.com/saugo360/https-medium-com-saugo360-flutter-using-overlay-to-display-floating-widgets-2e6d0e8decb9 (who actually is the same plugin OP) and then wrapped where it had:

      ListTile(
                  title: Text('Syria'),
                  onTap: () {
                    print('Syria Tapped');
                  },
                ),

To

      GestureDetector(
  onPanDown: (_) {
       print('Syria tapped);
 },
   child: ListTile(
           title: Text('Syria'),
                ),
),

shadowdogg avatar Jun 01 '20 09:06 shadowdogg

There is a workaround in #151 by user @jquintana53 that I used and it worked for me:

itemBuilder: (context, String suggestion) {
           return Listener(
             child: Container(
               color: Colors.black, // <-- this gets rid of the highlight that's not centered on the mouse
               child: ListTile(
                 title: Text(suggestion),
               ),
             ),
             onPointerDown: () {
                 print(suggestion);
                // Do what you would have done in onSuggestionSelected()  here
              },
           );
         },

wterrill avatar Jun 02 '20 19:06 wterrill

@wterrill I wish the author would mention this. Thanks a lot for letting me know about this.

shadowdogg avatar Jun 03 '20 00:06 shadowdogg

This package is only tested on App programs, not Web etc. There are lots of issues with desktop/Web applications beyond what this plugin can handle.

sjmcdowall avatar Jun 03 '20 00:06 sjmcdowall

@shadowdogg thank you this solution worked. I didn't know GestureDetector has this onPanDown callback function which can detect mouse events. @wterrill thank you your solution works as well but I saw that many callback functions from Listener for mouse events are now deprecated somehow. Although the mouse clicks are now detected the suggestion list behaves in a way that when hovering over an element the previous list element is being highlighted while the actual one is still clicked and selected

bytejutsu avatar Jun 04 '20 20:06 bytejutsu

I looked more closely at @shadowdogg's answer, and I realized that I didn't understand it at first. So, just for the next guy, I'll make the code below more obvious. (it just needs to be wrapped with an itemBuilder so that it can go directly into the TypeAheadField widget):

itemBuilder: (context, String suggestion) {
            return GestureDetector(
              onPanDown: (_) {
                print(suggestion);
              },
                child: ListTile(
                  dense: true,
                  title: Text(suggestion),
                ),
             );
          },

(and, of course, by doing this, you still need the 'onSuggestionSelected' method, but you can leave it blank.

wterrill avatar Jun 04 '20 21:06 wterrill

Any advantage of doing Listener over Gesture detection?

@wterill True I probably didn't make it very clear to this example exactly.

onPanDown: (_) => this._typeAheadController.text = suggestion,

For anyone who didn't realise too, to set the text

shadowdogg avatar Jun 04 '20 22:06 shadowdogg

I looked more closely at @shadowdogg's answer, and I realized that I didn't understand it at first. So, just for the next guy, I'll make the code below more obvious. (it just needs to be wrapped with an itemBuilder so that it can go directly into the TypeAheadField widget):

itemBuilder: (context, String suggestion) {
            return GestureDetector(
              onPanDown: (_) {
                print(suggestion);
              },
                child: ListTile(
                  dense: true,
                  title: Text(suggestion),
                ),
             );
          },

(and, of course, by doing this, you still need the 'onSuggestionSelected' method, but you can leave it blank.

onPanDown workaround makes it impossible to scroll through the suggestion list on web version of app on mobile device

SeriousMonk avatar Oct 25 '22 10:10 SeriousMonk

just for your information: https://pub.dev/packages/flutter_keyboard_visibility

Ahmadre avatar Jan 25 '23 15:01 Ahmadre

I already solved the error with keyboard visibility, but still: it's not working. So it's definetly an architectual error here.

Ahmadre avatar Jan 25 '23 15:01 Ahmadre