mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Updated Stateless and Stateful widget docstrings (#95407)
This commit is contained in:
parent
c746be6626
commit
d571257a99
@ -438,6 +438,14 @@ abstract class Widget extends DiagnosticableTree {
|
||||
/// * Use `const` widgets where possible, and provide a `const` constructor for
|
||||
/// the widget so that users of the widget can also do so.
|
||||
///
|
||||
/// * When trying to create a reusable piece of UI, prefer using a widget
|
||||
/// rather than a helper method. For example, if there was a function used to
|
||||
/// build a widget, a [State.setState] call would require Flutter to entirely
|
||||
/// rebuild the returned wrapping widget. If a [Widget] was used instead,
|
||||
/// Flutter would be able to efficiently re-render only those parts that
|
||||
/// really need to be updated. Even better, if the created widget is `const`,
|
||||
/// Flutter would short-circuit most of the rebuild work.
|
||||
///
|
||||
/// * Consider refactoring the stateless widget into a stateful widget so that
|
||||
/// it can use some of the techniques described at [StatefulWidget], such as
|
||||
/// caching common parts of subtrees and using [GlobalKey]s when changing the
|
||||
@ -646,11 +654,20 @@ abstract class StatelessWidget extends Widget {
|
||||
/// efficient for a widget to be re-used than for a new (but
|
||||
/// identically-configured) widget to be created. Factoring out the stateful
|
||||
/// part into a widget that takes a child argument is a common way of doing
|
||||
/// this.
|
||||
/// this. Another caching strategy consists of assigning a widget to a
|
||||
/// `final` state variable which can be used in the build method.
|
||||
///
|
||||
/// * Use `const` widgets where possible. (This is equivalent to caching a
|
||||
/// widget and re-using it.)
|
||||
///
|
||||
/// * When trying to create a reusable piece of UI, prefer using a widget
|
||||
/// rather than a helper method. For example, if there was a function used to
|
||||
/// build a widget, a [State.setState] call would require Flutter to entirely
|
||||
/// rebuild the returned wrapping widget. If a [Widget] was used instead,
|
||||
/// Flutter would be able to efficiently re-render only those parts that
|
||||
/// really need to be updated. Even better, if the created widget is `const`,
|
||||
/// Flutter would short-circuit most of the rebuild work.
|
||||
///
|
||||
/// * Avoid changing the depth of any created subtrees or changing the type of
|
||||
/// any widgets in the subtree. For example, rather than returning either the
|
||||
/// child or the child wrapped in an [IgnorePointer], always wrap the child
|
||||
|
Loading…
Reference in New Issue
Block a user