简体   繁体   English

Dart&Flutter:如何等待请求结果

[英]Dart & Flutter: How to wait for request result

I need to fetch dictionaries from internet before user will be able to use my application. 我需要从互联网上获取字典,然后用户才能使用我的应用程序。 I have a logon screen and then user is redirected to form where dropdown lists are populated and used. 我有一个登录屏幕,然后将用户重定向到填充并使用下拉列表的表单。 The problem occurs from time to time, when requests aren't completed yet due them asynchronous nature but view is already rendered. 问题有时会发生,当请求尚未完成时(由于它们具有异步特性,但视图已经呈现)。 Is there any smart way, to wait for http requests? 有什么聪明的方法来等待http请求吗?

The cleanest solution is probably to initially direct to a loading screen and navigate to the screen showing content in the callback from your server call. 最干净的解决方案可能是最初定向到加载屏幕,然后导航到显示服务器调用中回调内容的屏幕。

Alternatively you could also handle that within the same screen with a loading state. 或者,您也可以在具有加载状态的同一屏幕中处理该问题。

Examples see here or here . 示例请参见此处此处

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

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