Flutter:Streambuilder-关闭流 [英] Flutter: Streambuilder - Closing of streams

查看:398
本文介绍了Flutter:Streambuilder-关闭流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,该应用程序大量使用streambuilder从应用程序的多个页面中从Firestore获取实时数据.

I'm in the process of building an app which uses streambuilder heavily for getting realtime data from firestore across multiple pages in the app.

由于没有关闭流/取消流订阅的方法,因此可以安全地假设在框架处理小部件时,streambuilder将自动分离侦听Firestore文档的更改吗?有什么需要注意的警告.

As there is no stream close / stream subscription cancellation methods, is it safe to assume that streambuilder will auto detach listening to Firestore document changes when the widget is disposed by framework? Are there any caveats to be aware of.

谢谢.

推荐答案

当从流树中永久删除订阅该流的窗口小部件时, StreamBuilder 将自动关闭其关联的流:

A StreamBuilder closes its associated stream automatically when the widget subscribing to the stream is permanently removed from the widget tree:

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/async.dart#L129

或者是一个永久性的示例,如果master分支的链接有一天不可用:

Or a permanent example if the link the master branch won't work one day:

https://github.com/flutter/flutter/blob/2ece1c3a174c3dd7099736f13b4ad16bb9b70c1d/packages/flutter/lib/src/widgets/async.dart#L131

这篇关于Flutter:Streambuilder-关闭流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆