简体   繁体   English

Flutter:实时API数据获取

[英]Flutter: Realtime API data fetch

I came across to this one solution where we need to use Timer() in order to fetch the changes over time and add to stream controller.我遇到了一个解决方案,我们需要使用 Timer() 来获取随时间的变化并添加到 stream controller。 Just a simple question, does this method will consume more internet usage for the user?只是一个简单的问题,这种方法是否会为用户消耗更多的互联网使用量?

Because, even the API data does not have new value, the apps still will fetch the API when the period in Timer() reach, which I consider this is just waste of process and internet usage.因为,即使 API 数据没有新值,当 Timer() 中的时间段到达时,应用程序仍然会获取 API,我认为这只是浪费进程和互联网使用。

You mentioned the use of a stream in your post, hence if your API implements a stream too, you do not need to use a Timer() to make requests (also known as Polling).您在帖子中提到了使用 stream,因此,如果您的 API 也实现了 stream,则您也不需要使用计时器()来发出请求(也称为轮询)。

You just need to subscribe to your API stream to receive updated data.您只需订阅您的 API stream 即可接收更新的数据。

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

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