Unverified Commit 28fc34c0 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Update docs for initstate(), didUpdateWidget(), dispose() (#27501)

parent 9f7ab4c4
...@@ -44,6 +44,20 @@ export 'package:flutter/rendering.dart' show RenderObject, RenderBox, debugDumpR ...@@ -44,6 +44,20 @@ export 'package:flutter/rendering.dart' show RenderObject, RenderBox, debugDumpR
/// `children` property, and then provide the children to that widget. /// `children` property, and then provide the children to that widget.
/// {@endtemplate} /// {@endtemplate}
/// {@template flutter.widgets.subscriptions}
/// If a [State]'s [build] method depends on an object that can itself
/// change state, for example a [ChangeNotifier] or [Stream], or some
/// other object to which one can subscribe to receive notifications, then
/// be sure to subscribe and unsubscribe properly in [initState],
/// [didUpdateWidget], and [dispose]:
///
/// * In [initState], subscribe to the object.
/// * In [didUpdateWidget] unsubscribe from the old object and subscribe
/// to the new one if the updated widget configuration requires
/// replacing the object.
/// * In [dispose], unsubscribe from the object.
/// {@endtemplate}
// KEYS // KEYS
/// A key that is only equal to itself. /// A key that is only equal to itself.
...@@ -982,12 +996,7 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable { ...@@ -982,12 +996,7 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable {
/// location at which this object was inserted into the tree (i.e., [context]) /// location at which this object was inserted into the tree (i.e., [context])
/// or on the widget used to configure this object (i.e., [widget]). /// or on the widget used to configure this object (i.e., [widget]).
/// ///
/// If a [State]'s [build] method depends on an object that can itself change /// {@macro flutter.widgets.subscriptions}
/// state, for example a [ChangeNotifier] or [Stream], or some other object to
/// which one can subscribe to receive notifications, then the [State] should
/// subscribe to that object during [initState], unsubscribe from the old
/// object and subscribe to the new object when it changes in
/// [didUpdateWidget], and then unsubscribe from the object in [dispose].
/// ///
/// You cannot use [BuildContext.inheritFromWidgetOfExactType] from this /// You cannot use [BuildContext.inheritFromWidgetOfExactType] from this
/// method. However, [didChangeDependencies] will be called immediately /// method. However, [didChangeDependencies] will be called immediately
...@@ -1016,12 +1025,7 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable { ...@@ -1016,12 +1025,7 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable {
/// The framework always calls [build] after calling [didUpdateWidget], which /// The framework always calls [build] after calling [didUpdateWidget], which
/// means any calls to [setState] in [didUpdateWidget] are redundant. /// means any calls to [setState] in [didUpdateWidget] are redundant.
/// ///
/// If a [State]'s [build] method depends on an object that can itself change /// {@macro flutter.widgets.subscriptions}
/// state, for example a [ChangeNotifier] or [Stream], or some other object to
/// which one can subscribe to receive notifications, then the [State] should
/// subscribe to that object during [initState], unsubscribe from the old
/// object and subscribe to the new object when it changes in
/// [didUpdateWidget], and then unsubscribe from the object in [dispose].
/// ///
/// If you override this, make sure your method starts with a call to /// If you override this, make sure your method starts with a call to
/// super.didUpdateWidget(oldWidget). /// super.didUpdateWidget(oldWidget).
...@@ -1174,12 +1178,7 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable { ...@@ -1174,12 +1178,7 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable {
/// Subclasses should override this method to release any resources retained /// Subclasses should override this method to release any resources retained
/// by this object (e.g., stop any active animations). /// by this object (e.g., stop any active animations).
/// ///
/// If a [State]'s [build] method depends on an object that can itself change /// {@macro flutter.widgets.subscriptions}
/// state, for example a [ChangeNotifier] or [Stream], or some other object to
/// which one can subscribe to receive notifications, then the [State] should
/// subscribe to that object during [initState], unsubscribe from the old
/// object and subscribe to the new object when it changes in
/// [didUpdateWidget], and then unsubscribe from the object in [dispose].
/// ///
/// If you override this, make sure to end your method with a call to /// If you override this, make sure to end your method with a call to
/// super.dispose(). /// super.dispose().
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment