flutter_typeahead icon indicating copy to clipboard operation
flutter_typeahead copied to clipboard

[Bug] hideWithKeyboard: false does not prevent hiding

Open milindgoel15 opened this issue 8 months ago • 5 comments

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

milindgoel15 avatar Dec 10 '23 12:12 milindgoel15

Reproducible on 5.0.1

clragon avatar Dec 13 '23 17:12 clragon

I have the same issue . flutter_typeahead 5.0.2

Screenshot_1705829838

ilyasarafath avatar Jan 21 '24 09:01 ilyasarafath

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.

clragon avatar Jan 27 '24 19:01 clragon

How was it not an issue before?

milindgoel15 avatar Jan 28 '24 02:01 milindgoel15

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.

clragon avatar Feb 08 '24 22:02 clragon