Flutter:Streambuilder-关闭流 [英] Flutter: Streambuilder - Closing of streams
问题描述
我正在构建一个应用程序,该应用程序大量使用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:
这篇关于Flutter:Streambuilder-关闭流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!