简体   繁体   English

异步加载下拉菜单-Flutter

[英]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: 本质上,我正在尝试做出类似以下的事情: 在此处输入图片说明

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. 我已经找到并清除了标志,国家及其代码列表,并构建了为任意索引创建DropdownMenuItem的方法。 I then construct a list of them and pass it to the DropdownButton widget. 然后,我构造它们的列表,并将其传递给DropdownButton小部件。 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? 下拉菜单是否可以加载所选索引周围的前10个左右的小部件并显示它们,因为这些部件最初将在视图中显示,然后异步加载其余的小部件? 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. 我怀疑这将需要一个自定义的下拉菜单,但是我对Flutter的下拉菜单的实现不是很精通,所以我不确定如何进行此操作。

Any help is appreciated. 任何帮助表示赞赏。

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. 您可以使用类似ListView.builder这样的按需构建项目的方法来改善这种情况。

It seems like the default dropdown system is not based on a ListView . 似乎默认的下拉列表系统不是基于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. 或者,使用带有嵌入式ListView的SimpleDialog之类的东西来显示列表。 Like this one for Android. 这样的Android版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM