salim-lachdhaf / dropdown_search

Simple and robust Dropdown with item search feature, making it possible to use an offline item list or filtering URL for easy customization.
MIT License
346 stars 333 forks source link

Selected item shown twice in the dropdown #345

Closed nilpkthmsk closed 2 years ago

nilpkthmsk commented 2 years ago

I use onFind to filter the items list for the dropdown, but the selected on will be duplicated, and shown twice in the dropdown. Any work around ?

Screen Shot 2022-01-12 at 1 31 58

Thank you in advance.

salim-lachdhaf commented 2 years ago

which version are using ?

nilpkthmsk commented 2 years ago

It's version 2.0.1.

salim-lachdhaf commented 2 years ago

could you past an example of your code

nilpkthmsk commented 2 years ago

  DropdownSearch(
    mode: Mode.BOTTOM_SHEET,
    dropdownSearchDecoration: InputDecoration(
      labelText: context.localeString("Currency"),
      hintText: context.localeString("Currency Hint"),
      contentPadding:
          const EdgeInsets.fromLTRB(12, 12, 0, 0),
      border: const OutlineInputBorder(),
    ),
    showSearchBox: true,
    // showClearButton: true,
    searchFieldProps: TextFieldProps(
        decoration: InputDecoration(
      labelText: context.localeString("Currency Search"),
      contentPadding: const EdgeInsets.all(12),
      border: const OutlineInputBorder(),
    )),
    items: Currency.list,
    onChanged: (CurrencyUnit? c) => {Currency.save(c!)},
    onFind: (String? filter) =>
        Currency.findAll(keyword: filter),
    itemAsString: (CurrencyUnit? c) => c.toString(),
    selectedItem: Currency.load(),
  ),

For Currency.findAll, I use the filter to make list, and return the new list with it.

salim-lachdhaf commented 2 years ago

i think you have somthinng wrong in your data. try to use isFilteredOnline to true

nilpkthmsk commented 2 years ago

I tried setting the isFilteredOnline to true, but the result remains the same. I tried to print the data in the filter function, and it is like below.


flutter: THB
flutter: 1

THB = filtered text 1 = length of the list return The same result goes for no isFilteredOnline setting. And I found another error, don't know if it's related.


#0      _validateRpcStringParam (package:flutter_tools/src/vmservice.dart:377:5)
#1      setUpVmService. (package:flutter_tools/src/vmservice.dart:236:33)
#2      setUpVmService. (package:flutter_tools/src/vmservice.dart:234:60)
#3      VmService._routeRequest (package:vm_service/src/vm_service.dart:2253:27)
#4      VmService._processRequest (package:vm_service/src/vm_service.dart:2223:25)
#5      VmService._processMessageStr (package:vm_service/src/vm_service.dart:2190:9)
#6      _rootRunUnary (dart:async/zone.dart:1436:47)
#7      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#8      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#10     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#11     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#12     _StreamController._add (dart:async/stream_controller.dart:607:7)
#13     _StreamController.add (dart:async/stream_controller.dart:554:5)
#14     new _WebSocketImpl._fromSocket. (dart:_http/websocket_impl.dart:1144:21)
#15     _rootRunUnary (dart:async/zone.dart:1436:47)
#16     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#17     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#18     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#19     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#20     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
#21     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
#22     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:332:23)
#23     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:226:46)
#24     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#25     _rootRunUnary (dart:async/zone.dart:1436:47)
#26     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#27     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#28     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#29     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#30     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#31     _StreamController._add (dart:async/stream_controller.dart:607:7)
#32     _StreamController.add (dart:async/stream_controller.dart:554:5)
#33     _Socket._onData (dart:io-patch/socket_patch.dart:2302:41)
#34     _rootRunUnary (dart:async/zone.dart:1444:13)
#35     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#36     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#37     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#38     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#39     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#40     _StreamController._add (dart:async/stream_controller.dart:607:7)
#41     _StreamController.add (dart:async/stream_controller.dart:554:5)
#42     new _RawSocket. (dart:io-patch/socket_patch.dart:1830:33)
#43     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1314:14)
#44     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#45     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#46     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:122:13)
#47     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:193:5)

reke592 commented 2 years ago

I encounter the same issue, just remove the onFind function, it seems like the itemAsString is enough

nilpkthmsk commented 2 years ago

I encounter the same issue, just remove the onFind function, it seems like the itemAsString is enough

Oh it works now. Thank you so much.