Positioning / Selecting a widget depending on the position / size of another widget

Several times I came across a rather large wall in Flutter. Animating or creating widgets that depend on other widgets to get their size / position.

Some examples of what might be my worst nightmare of trepidation: Quickly bind a widget next to each other. In css we will have the following:

.root {
    display: flex;
    background: grey;
    padding: 4px;
}
.root > div {
  background: lightgrey;
  margin-right: 5px;
  padding: 5px;
}
<div class="root">
    <div>
         dynamic height
         <br/>
         dynamic width
         <br/>
         fat
         <br/>
         super fat
    </div>
    <div>
         dynamic width
         <br/>
         dynamic height
    </div>
</div>
Run codeHide result
  • the parent accepts the entire width (not important).
  • the parent takes the height of the largest children.
  • smaller children to match the parent
  • children are located next to each other.

In awe, I do not think that we can have all 4 points at once.

And now, if we have 2 of these lists and animations, where does one item move from one list to another? Example

enter image description here enter image description here

. , SlideTransition, , ? :

enter image description here

. . : - ( / )? -, ?

+4
1

, , IntrinsicHeight CrossAxisAlignment.stretch. :

screenshot

:

import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Padding(
        padding: new EdgeInsets.all(10.0),
        child: new IntrinsicHeight(
          child: new Container(
            color: Colors.grey,
            padding: new EdgeInsets.all(4.0),
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                new Container(
                  padding: new EdgeInsets.all(5.0),
                  margin: new EdgeInsets.only(right: 5.0),
                  color: Colors.grey[200],
                  child: new Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      new Text('dynamic height'),
                      new Text('dynamic width'),
                      new Text('fat'),
                      new Text('super fat'),
                    ],
                  ),
                ),
                new Container(
                  padding: new EdgeInsets.all(5.0),
                  color: Colors.grey[200],
                  child: new Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      new Text('dynamic width'),
                      new Text('dynamic height'),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

, CustomMultiChildLayout . . :

screenshot

+1

Source: https://habr.com/ru/post/1684859/


All Articles