crawlinknetworks / dropdown_plus

Simple and easy to use Dropdown in forms with search, keyboard navigation, offiline data source, remote data source and easy customization.
MIT License
12 stars 43 forks source link

KeyEventResult #18

Open ghost opened 2 years ago

ghost commented 2 years ago

Hi,

When using the example and then type in the search DropdownFormField this error message is produced. Each keystroke produces this error.

Using Chrome as the browser.

Paul Brassington

════════ Exception caught by services library ══════════════════════════════════ The following TypeErrorImpl was thrown while processing the key message handler: Expected a value of type 'KeyEventResult', but got one of type 'bool'

SaharatPr commented 2 years ago

me too

Adeel-Sultan commented 2 years ago

@SaharatPr @HASHCAPDOTCOM @crawlinknetworks @namdegnah anyone found solution ? please let us know

siddiquisahil02 commented 2 years ago

@Adeel-Sultan @SaharatPr @HASHCAPDOTCOM Yea, I found a solution, but you'll have to change some lines in the package files as the focus widget, onKey is going to be deprecated soon, so use onKeyEvent and change some lines of a code in the package itself.

in the dropdown.dart (implementation file of DropdownFormField widget) file of the package, replace _onKeyPressed function with this code

_onKeyPressed(KeyEvent event) {
    //print('_onKeyPressed : ${event.character}');
    if (event.logicalKey==LogicalKeyboardKey.enter) {
      if (_searchFocusNode.hasFocus) {
        _toggleOverlay();
      } else {
        _toggleOverlay();
      }
      //return false;
      return KeyEventResult.ignored;
    } else if (event.logicalKey==LogicalKeyboardKey.escape) {
      _removeOverlay();
      return KeyEventResult.handled;
      //return true;
    } else if (event.logicalKey==LogicalKeyboardKey.arrowDown) {
      int v = _listItemFocusedPosition;
      v++;
      if (v >= _options!.length) v = 0;
      _listItemFocusedPosition = v;
      _listItemsValueNotifier.value = List<T>.from(_options ?? []);
      //return true;
      return KeyEventResult.handled;
    } else if (event.logicalKey==LogicalKeyboardKey.arrowUp) {
      int v = _listItemFocusedPosition;
      v--;
      if (v < 0) v = _options!.length - 1;
      _listItemFocusedPosition = v;
      _listItemsValueNotifier.value = List<T>.from(_options ?? []);
      //return true;
      return KeyEventResult.handled;
    }
    return KeyEventResult.ignored;
    //return false;
  }

And RawKeyEvent is now will be replaced by KeyEvent and don't forget to restart/reinstall the application after saving these changes, for these to take effect.

Adeel-Sultan commented 2 years ago

@Adeel-Sultan @SaharatPr @HASHCAPDOTCOM Yea, I found a solution, but you'll have to change some lines in the package files as the focus widget, onKey is going to be deprecated soon, so use onKeyEvent and change some lines of a code in the package itself.

in the dropdown.dart (implementation file of DropdownFormField widget) file of the package, replace _onKeyPressed function with this code

_onKeyPressed(KeyEvent event) {
    //print('_onKeyPressed : ${event.character}');
    if (event.logicalKey==LogicalKeyboardKey.enter) {
      if (_searchFocusNode.hasFocus) {
        _toggleOverlay();
      } else {
        _toggleOverlay();
      }
      //return false;
      return KeyEventResult.ignored;
    } else if (event.logicalKey==LogicalKeyboardKey.escape) {
      _removeOverlay();
      return KeyEventResult.handled;
      //return true;
    } else if (event.logicalKey==LogicalKeyboardKey.arrowDown) {
      int v = _listItemFocusedPosition;
      v++;
      if (v >= _options!.length) v = 0;
      _listItemFocusedPosition = v;
      _listItemsValueNotifier.value = List<T>.from(_options ?? []);
      //return true;
      return KeyEventResult.handled;
    } else if (event.logicalKey==LogicalKeyboardKey.arrowUp) {
      int v = _listItemFocusedPosition;
      v--;
      if (v < 0) v = _options!.length - 1;
      _listItemFocusedPosition = v;
      _listItemsValueNotifier.value = List<T>.from(_options ?? []);
      //return true;
      return KeyEventResult.handled;
    }
    return KeyEventResult.ignored;
    //return false;
  }

And RawKeyEvent is now will be replaced by KeyEvent and don't forget to restart/reinstall the application after saving these changes, for these to take effect.

@HASHCAPDOTCOM could you please change this in file and check if work, updates all files and update library too?

siddiquisahil02 commented 2 years ago

@HASHCAPDOTCOM could you please change this in file and check if work, updates all files and update library too?

Yes, I have verified, it is working now and I have also created a pull request with all the changes.

siddiquisahil02 commented 2 years ago

@Adeel-Sultan @SaharatPr @namdegnah I just created my own package for Dropdown Text Search with keyboard support, feel free to check it out. Thank you

dropdown_text_search: ^0.0.1
Bes79 commented 2 years ago

same issue