Skip to content

Commit 52f923c

Browse files
Add documentation for best practices for StreamBuilder like FutureBuilder (#143295)
Fixes flutter/flutter#142189
1 parent cf2c684 commit 52f923c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/flutter/lib/src/widgets/async.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,20 @@ typedef AsyncWidgetBuilder<T> = Widget Function(BuildContext context, AsyncSnaps
321321
///
322322
/// {@youtube 560 315 https://www.youtube.com/watch?v=MkKEWHfy99Y}
323323
///
324+
/// ## Managing the stream
325+
///
326+
/// The [stream] must have been obtained earlier, e.g. during [State.initState],
327+
/// [State.didUpdateWidget], or [State.didChangeDependencies]. It must not be
328+
/// created during the [State.build] or [StatelessWidget.build] method call when
329+
/// constructing the [StreamBuilder]. If the [stream] is created at the same
330+
/// time as the [StreamBuilder], then every time the [StreamBuilder]'s parent is
331+
/// rebuilt, the asynchronous task will be restarted.
332+
///
333+
/// A general guideline is to assume that every `build` method could get called
334+
/// every frame, and to treat omitted calls as an optimization.
335+
///
336+
/// ## Timing
337+
///
324338
/// Widget rebuilding is scheduled by each interaction, using [State.setState],
325339
/// but is otherwise decoupled from the timing of the stream. The [builder]
326340
/// is called at the discretion of the Flutter pipeline, and will thus receive a

0 commit comments

Comments
 (0)