mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
Add documentation for best practices for StreamBuilder
like FutureBuilder
(#143295)
Fixes https://github.com/flutter/flutter/issues/142189
This commit is contained in:
parent
cf2c68417f
commit
52f923c360
|
@ -321,6 +321,20 @@ typedef AsyncWidgetBuilder<T> = Widget Function(BuildContext context, AsyncSnaps
|
|||
///
|
||||
/// {@youtube 560 315 https://www.youtube.com/watch?v=MkKEWHfy99Y}
|
||||
///
|
||||
/// ## Managing the stream
|
||||
///
|
||||
/// The [stream] must have been obtained earlier, e.g. during [State.initState],
|
||||
/// [State.didUpdateWidget], or [State.didChangeDependencies]. It must not be
|
||||
/// created during the [State.build] or [StatelessWidget.build] method call when
|
||||
/// constructing the [StreamBuilder]. If the [stream] is created at the same
|
||||
/// time as the [StreamBuilder], then every time the [StreamBuilder]'s parent is
|
||||
/// rebuilt, the asynchronous task will be restarted.
|
||||
///
|
||||
/// A general guideline is to assume that every `build` method could get called
|
||||
/// every frame, and to treat omitted calls as an optimization.
|
||||
///
|
||||
/// ## Timing
|
||||
///
|
||||
/// Widget rebuilding is scheduled by each interaction, using [State.setState],
|
||||
/// but is otherwise decoupled from the timing of the stream. The [builder]
|
||||
/// is called at the discretion of the Flutter pipeline, and will thus receive a
|
||||
|
|
Loading…
Reference in a new issue