flutter_typeahead
flutter_typeahead copied to clipboard
[Bug] hideWithKeyboard: false does not prevent hiding
Hi,
so before the major upgrade, we were able to hide the keyboard while still keep the suggestions on screen. But since the upgrade, the boolean hideWithKeyboard
has no effect when set to either true or false.
Code
return TypeAheadField<PlaceModel>(
hideKeyboardOnDrag: false,
hideWithKeyboard: false,
controller: textFieldController,
debounceDuration: const Duration(milliseconds: 200),
builder: (context, controller, focusNode) {
return TextFormField(
// onTapOutside: (event) {
// focusNode.unfocus();
// },
focusNode: focusNode,
controller: controller,
style: const TextStyle(
decorationColor: Colors.white,
fontSize: 20,
),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
),
contentPadding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 12,
),
hintText: "Enter location",
labelText: "Location",
suffix: IconButton(
onPressed: () {
controller.clear();
},
color: Theme.of(context).colorScheme.primary,
icon: const Icon(Icons.clear),
),
),
);
},
suggestionsCallback: (pattern) async {
return await PlaceResponse.getPlacesAutocomplete(pattern);
},
itemSeparatorBuilder: (context, index) {
return const Divider();
},
itemBuilder: (context, suggestion) {
return ListTile(
leading: Icon(
Icons.location_searching_outlined,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
minLeadingWidth: 5,
title: Text(suggestion.name),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${suggestion.state.isNotEmpty ? '${suggestion.state}, ' : ''}${suggestion.country}",
),
Text(
'ID: ${suggestion.locId != '' ? suggestion.locId : 'n/a'}',
),
],
),
trailing: Text(
"${suggestion.lat.toStringAsFixed(2)}${DirectionNames.convertLatToGPS(suggestion.lat)} / ${suggestion.lon.toStringAsFixed(2)}${DirectionNames.convertLongToGPS(suggestion.lon)}",
),
);
},
transitionBuilder: (context, animation, child) {
return FadeTransition(
opacity: CurvedAnimation(
parent: animation,
curve: Curves.fastOutSlowIn,
),
child: child,
);
},
// animationStart: 1,
// animationDuration: Duration(milliseconds: 400),
errorBuilder: (context, error) => Text(
'$error',
style: TextStyle(
color: Theme.of(context).colorScheme.onError,
),
),
loadingBuilder: (context) => const ProgressAnimation(),
emptyBuilder: (context) => Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"No locations found",
style: TextStyle(
color: Theme.of(context).colorScheme.onBackground,
),
),
),
// minCharsForSuggestions: 1,
hideOnSelect: true,
onSelected: (suggestion) async {
fetchLocation(suggestion, textFieldController);
},
// onSaved: (value) => textFieldController.text = value!,
);
Screen recording
https://github.com/AbdulRahmanAlHamali/flutter_typeahead/assets/45682747/6a475d4e-0703-49ae-a3e3-dcba7842ffc0
Reproducible on 5.0.1
I have the same issue . flutter_typeahead 5.0.2
The underlying issue here is that the suggestions box is closed when the textfield loses focus. Because closing the keyboard will unfocus the textfield, the suggestions box will close.
I dont really know how we could solve this. The code cannot distinguish between losing focus because the focus was shifted and losing focus because the keyboard was closed.
As a workaround, you can disable closing the suggestions box when focus is lost (hideOnUnfocus: false
), but then you will have to manually close the box when the user taps outside. You can use a SuggestionsController
to close the box manually.
How was it not an issue before?
Unfortunately I do not know that. The previous code base was very different from the current one. I will investigate it when I have time.