Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Streambuilder - Closing of streams

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.

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.

Thanks.

like image 423
Raghu Avatar asked Apr 13 '19 05:04

Raghu


1 Answers

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

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

like image 133
17 revs, 13 users 59% Avatar answered Sep 27 '22 18:09

17 revs, 13 users 59%