forked from firka/flutter
Add LayoutBuilder example (#61948)
This commit is contained in:
@@ -247,6 +247,59 @@ mixin RenderConstrainedLayoutBuilder<ConstraintType extends Constraints, ChildTy
|
||||
/// in an [Align] widget. If the child might want to be bigger, consider
|
||||
/// wrapping it in a [SingleChildScrollView] or [OverflowBox].
|
||||
///
|
||||
/// {@tool dartpad --template=stateless_widget_material}
|
||||
///
|
||||
/// This example uses a [LayoutBuilder] to build a different widget depending on the available width. Resize the
|
||||
/// DartPad window to see [LayoutBuilder] in action!
|
||||
///
|
||||
/// ```dart
|
||||
/// Widget build(BuildContext context) {
|
||||
/// return Scaffold(
|
||||
/// appBar: AppBar(title: Text("LayoutBuilder Example")),
|
||||
/// body: LayoutBuilder(
|
||||
/// builder: (context, constraints) {
|
||||
/// if (constraints.maxWidth > 600) {
|
||||
/// return _buildWideContainers();
|
||||
/// } else {
|
||||
/// return _buildNormalContainer();
|
||||
/// }
|
||||
/// },
|
||||
/// ),
|
||||
/// );
|
||||
/// }
|
||||
///
|
||||
/// Widget _buildNormalContainer() {
|
||||
/// return Center(
|
||||
/// child: Container(
|
||||
/// height: 100.0,
|
||||
/// width: 100.0,
|
||||
/// color: Colors.red,
|
||||
/// ),
|
||||
/// );
|
||||
/// }
|
||||
///
|
||||
/// Widget _buildWideContainers() {
|
||||
/// return Center(
|
||||
/// child: Row(
|
||||
/// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
/// children: <Widget>[
|
||||
/// Container(
|
||||
/// height: 100.0,
|
||||
/// width: 100.0,
|
||||
/// color: Colors.red,
|
||||
/// ),
|
||||
/// Container(
|
||||
/// height: 100.0,
|
||||
/// width: 100.0,
|
||||
/// color: Colors.yellow,
|
||||
/// ),
|
||||
/// ],
|
||||
/// ),
|
||||
/// );
|
||||
/// }
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [SliverLayoutBuilder], the sliver counterpart of this widget.
|
||||
|
||||
Reference in New Issue
Block a user