Unverified Commit 0a03d643 authored by songyiYu's avatar songyiYu Committed by GitHub

Add LayoutBuilder example (#61948)

parent 7c942e39
......@@ -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.
......
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