icemanbsi / searchable_dropdown

MIT License
107 stars 162 forks source link

Initial value of selected item #66

Closed PhilDevs94 closed 4 years ago

PhilDevs94 commented 4 years ago

Hello, first I want to thank you for this awsome plug-in, but I meet some problems when working on the project I have cities list from sever:

cities = ['A','B','C'];

And the customer information I fetch from the server

customer = { "name" : "Customer A", "city" : "A" ( this value can be null) }

I'm working on a project which fetches data of customer from the server, the thing is I want to check whether the city value is null or not if it's not null I want to set to the initial value of the SearchableDropdown.single() to the customer information but I cannot see the field how to set initial value, I hope you can help me out, thank you

PhilDevs94 commented 4 years ago

I found a solution, this may help who met problems like me, You just initial an empty array of dropdownlistItem and listen to the state of API fetching, when it's completed, then you fetch it to the UI, here is an example: var items = new List<DropdownListItem>(); new SearchableDropdown.single( items: state is FetchedList ? state.items : items, value: ..... );