Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronously loading drop down menu - Flutter

I am trying to build a form with a phone input that includes country codes. Essentially, I am trying to make something a lot like this: enter image description here

I already found and cleaned a list of flags, countries, and their codes, and built the method that creates a DropdownMenuItem for an arbitrary index. I then construct a list of them and pass it to the DropdownButton widget. It's all very simple, so I don't think the code is necessary. However, because I have so many countries, and therefore menu items, the menu lags significantly when opening. So, I was wondering if drop down menus are capable of loading large numbers of widgets in a smarter fashion than it seems they do.

Can a drop down menu could load the first 10 or so widgets around the selected index and display them, as that is all that will be in view initially, and then load the rest of the widgets asynchronously? I suspect that this will require a custom drop down menu, but I am not very well versed in the implementation of Flutter's drop down menu, so I am unsure of how to proceed with this.

Any help is appreciated.

like image 352
acn3 Avatar asked Aug 05 '26 09:08

acn3


1 Answers

I don't think that "loading" is the actual problem here, more likely it's the rendering/building of the widgets. You can improve the situation by using something like a ListView.builder that builds items on demand.

It seems like the default dropdown system is not based on a ListView.

You can create your own version of the dropdown (like a complete customized copy of the classes), which will require quite quite a lot of work and research.

Or alternatively, use something like a SimpleDialog with an embedded ListView to display the list. Like this one for Android.

like image 151
boformer Avatar answered Aug 08 '26 00:08

boformer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!