Showing
2 changed files
with
28 additions
and
0 deletions
| @@ -675,6 +675,33 @@ class Builder extends StatelessWidget { | @@ -675,6 +675,33 @@ class Builder extends StatelessWidget { | ||
| 675 | Widget build(Context context) => builder(context); | 675 | Widget build(Context context) => builder(context); |
| 676 | } | 676 | } |
| 677 | 677 | ||
| 678 | +/// The signature of the [LayoutBuilder] builder function. | ||
| 679 | +typedef LayoutWidgetBuilder = Widget Function( | ||
| 680 | + Context context, BoxConstraints constraints); | ||
| 681 | + | ||
| 682 | +/// Builds a widget tree that can depend on the parent widget's size. | ||
| 683 | +class LayoutBuilder extends StatelessWidget { | ||
| 684 | + /// Creates a widget that defers its building until layout. | ||
| 685 | + LayoutBuilder({ | ||
| 686 | + @required this.builder, | ||
| 687 | + }) : assert(builder != null); | ||
| 688 | + | ||
| 689 | + /// Called at layout time to construct the widget tree. | ||
| 690 | + final LayoutWidgetBuilder builder; | ||
| 691 | + | ||
| 692 | + BoxConstraints _constraints; | ||
| 693 | + | ||
| 694 | + @override | ||
| 695 | + void layout(Context context, BoxConstraints constraints, | ||
| 696 | + {bool parentUsesSize = false}) { | ||
| 697 | + _constraints = constraints; | ||
| 698 | + super.layout(context, constraints); | ||
| 699 | + } | ||
| 700 | + | ||
| 701 | + @override | ||
| 702 | + Widget build(Context context) => builder(context, _constraints); | ||
| 703 | +} | ||
| 704 | + | ||
| 678 | class FullPage extends SingleChildWidget { | 705 | class FullPage extends SingleChildWidget { |
| 679 | FullPage({ | 706 | FullPage({ |
| 680 | @required this.ignoreMargins, | 707 | @required this.ignoreMargins, |
-
Please register or login to post a comment