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#L131
或者一个永久的例子,如果 master 分支的链接有一天不起作用:
Or a permanent example if the link the master branch won't work one day:
这篇关于Flutter:Streambuilder - 关闭流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!