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

[Bug] hideWithKeyboard: false does not prevent hiding #548

Open
milindgoel15 opened this issue Dec 10, 2023 · 5 comments
Open

[Bug] hideWithKeyboard: false does not prevent hiding #548

milindgoel15 opened this issue Dec 10, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@milindgoel15
Copy link

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
hideWithKeyboard.mp4
@clragon clragon added the bug Something isn't working label Dec 10, 2023
@clragon clragon self-assigned this Dec 13, 2023
@clragon
Copy link
Collaborator

clragon commented Dec 13, 2023

Reproducible on 5.0.1

@ilyasarafath
Copy link

ilyasarafath commented Jan 21, 2024

I have the same issue .
flutter_typeahead 5.0.2

Screenshot_1705829838

@clragon
Copy link
Collaborator

clragon commented Jan 27, 2024

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.

@milindgoel15
Copy link
Author

How was it not an issue before?

@clragon clragon changed the title [Bug] the hideWithKeyboard when set to false not working as expected. [Bug] hideWithKeyboard: false does not prevent hiding Feb 3, 2024
@clragon
Copy link
Collaborator

clragon commented Feb 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants