AbdulRahmanAlHamali / flutter_typeahead

A TypeAhead widget for Flutter, where you can show suggestions to users as they type
BSD 2-Clause "Simplified" License
831 stars 349 forks source link

[Bug] OnSelected function not working in version:5.2.0 #600

Closed imshibl closed 3 months ago

imshibl commented 3 months ago

Steps to reproduce

  1. Create a list of string
  2. Use the created list of string with the flutter_typehead for auto compeletion suggestions
  3. try printing or performing any operations in the required onSelected function

Expected results

This code is supposed to print the value to the debug console. but it's not working. so i have used a gesture detector in the itemBuilder,that's way its working.

Actual results

The onSelected function is not invoking when pressed on the suggestion values

Package Version

5.2.0

Platform

Android, iOS

Code sample

Code sample ```dart TypeAheadField( controller: languageTextEditingController, itemBuilder: (context, language) { return GestureDetector( onTap: () { if (!selectedLanguages.contains(language)) { ref.read(selectedLanguageProvider.notifier).state = [ ...selectedLanguages, language, ]; } languageTextEditingController.clear(); }, child: ListTile( title: Text(language), ), ); }, builder: (context, controller, focusNode) { return TextField( controller: controller, focusNode: focusNode, decoration: InputDecoration( border: OutlineInputBorder( borderRadius: BorderRadius.circular(15), ), labelText: 'Language', ), ); }, emptyBuilder: (context) => const Padding( padding: EdgeInsets.all(8.0), child: Text( 'No languages found', style: TextStyle(fontSize: 16), ), ), suggestionsCallback: (search) { return languageListProvider .where( (language) => language.toLowerCase().contains( search.toLowerCase(), ), ) .toList(); }, onSelected: (value) { //not working on tap print("onSelected: $value"); }, ), ```

Logs

Logs ```console [Paste your logs here] ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]
clragon commented 3 months ago

Hi,

please do not add a GestureDetector into the item builder of the typeahead field. The typeahead field will already wrap your items with an InkWell that will call onSelected.

best regards.

imshibl commented 3 months ago

Hey, Thanks for the response.

Yah i understand. However i added GestureDetector because onSelected is not invoking

On Fri, 16 Aug 2024 at 9:23 PM, clragon @.***> wrote:

Hi,

please do not add a GestureDetector into the item builder of the typeahead field. The typeahead field will already wrap your items with an InkWell that will call onSelected.

best regards.

— Reply to this email directly, view it on GitHub https://github.com/AbdulRahmanAlHamali/flutter_typeahead/issues/600#issuecomment-2293754683, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOG3D7UCZBV3MSQ75QMFYOLZRYN6XAVCNFSM6AAAAABMSAIFJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTG42TINRYGM . You are receiving this because you authored the thread.Message ID: @.***>

clragon commented 3 months ago

Ah, right. It's because your code contains a ListTile, which swallows all pointer events, even when it has no onTap itself. You can either add the onTap to the ListTile and call select yourself by grabbing the SuggestionsController from context, or you can use an IgnorePointer around your ListTile, which is easier, but prevents all taps. In case you have extra elements inside your ListTile that should not trigger a selection, then you must to the former.

imshibl commented 3 months ago

Ok, thanks for the clarification.

On Fri, 16 Aug 2024 at 10:31 PM, clragon @.***> wrote:

Ah, right. It's because your code contains a ListTile, which swallows all pointer events, even when it has no onTap itself. You can either add the onTap to the ListTile and call select yourself by grabbing the SuggestionsController from context, or you can use an IgnorePointer around your ListTile, which is easier, but prevents all taps. In case you have extra elements inside your ListTile that should not trigger a selection, then you must to the former.

— Reply to this email directly, view it on GitHub https://github.com/AbdulRahmanAlHamali/flutter_typeahead/issues/600#issuecomment-2293851020, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOG3D7X5HMIKZABIEMOQUFTZRYV7DAVCNFSM6AAAAABMSAIFJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTHA2TCMBSGA . You are receiving this because you authored the thread.Message ID: @.***>

sharkfabri commented 2 months ago

I confirm, version 5.2.0 ignores onSelect, with or without onTap, with or without adding a IgnorePointer as parent Widget. Rolling back to version 5.1.0 works as a charme.