Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
bf6460f9
Unverified
Commit
bf6460f9
authored
Oct 15, 2020
by
Hans Muller
Committed by
GitHub
Oct 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated Builder API doc (#68151)
parent
e3184b38
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
2 deletions
+76
-2
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+76
-2
No files found.
packages/flutter/lib/src/widgets/basic.dart
View file @
bf6460f9
...
...
@@ -7155,13 +7155,87 @@ class KeyedSubtree extends StatelessWidget {
Widget
build
(
BuildContext
context
)
=>
child
;
}
/// A platonic widget that calls a closure to obtain its child widget.
/// A stateless utility widget whose [build] method uses its
/// [builder] callback to create the widget's child.
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=xXNOkIuSYuA}
///
/// This widget is a simple inline alternative to defining a [StatelessWidget]
/// subclass. For example a widget defined and used like this:
///
/// ```dart
/// class Foo extends StatelessWidget {
/// @override
/// Widget build(BuildContext context) => Text('foo');
/// }
///
/// Center(child: Foo())
/// ```
///
/// Could equally well be defined and used like this, without
/// definining a new widget class:
///
/// ```dart
/// Center(
/// child: Builder(
/// builder: (BuildContext context) => Text('foo');
/// ),
/// )
/// ```
///
/// The difference between either of the previous examples and simply
/// creating a child directly, without an intervening widget, is the
/// extra [BuildContext] element that the additional widget adds. This
/// is particularly noticeable when the tree contains an inherited
/// widget that is referred to by a method like [Scaffold.of],
/// which visits the child widget's BuildContext ancestors.
///
/// In the following example the button's `onPressed` callback is unable
/// to find the enclosing [ScaffoldState] with [Scaffold.of]:
///
/// ```dart
/// Widget build(BuildContext context) {
/// return Scaffold(
/// body: Center(
/// child: TextButton(
/// onPressed: () {
/// // Fails because Scaffold.of() doesn't find anything
/// // above this widget's context.
/// print(Scaffold.of(context).hasAppBar);
/// },
/// child: Text('hasAppBar'),
/// )
/// ),
/// );
/// }
/// ```
///
/// A [Builder] widget introduces an additional [BuildContext] element
/// and so the [Scaffold.of] method succeeds.
///
/// ```dart
/// Widget build(BuildContext context) {
/// return Scaffold(
/// body: Builder(
/// builder: (BuildContext context) {
/// return Center(
/// child: TextButton(
/// onPressed: () {
/// print(Scaffold.of(context).hasAppBar);
/// },
/// child: Text('hasAppBar'),
/// ),
/// );
/// },
/// ),
/// );
/// }
/// ```
///
/// See also:
///
/// * [StatefulBuilder], a platonic widget which also has state.
/// * [StatefulBuilder], A stateful utility widget whose [build] method uses its
/// [builder] callback to create the widget's child.
class
Builder
extends
StatelessWidget
{
/// Creates a widget that delegates its build to a callback.
///
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment