Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Constraint layout's equivalent in Flutter?

Can I position a widget based on another widget? like this:

Tiled Layout Without

flutter_staggered_grid_view Library

like image 327
david2020 Avatar asked Aug 20 '18 02:08

david2020


People also ask

What are constraints in Flutter?

A constraint is just a set of 4 doubles: a minimum and maximum width, and a minimum and maximum height. Then the widget goes through its own list of children. One by one, the widget tells its children what their constraints are (which can be different for each child), and then asks each child what size it wants to be.

What is the difference between scaffold and container in Flutter?

The scaffold has AppBar, Body, Bottom Navigation, Floating Action & Persistent Footer. The scaffold will give Material look and feel in Screen. Container: The container is a basic/common widget in Flutter which will contain other widgets.

How do you use rows and columns in Flutter?

To create a row or column in Flutter, you add a list of children widgets to a Row or Column widget. In turn, each child can itself be a row or column, and so on. The following example shows how it is possible to nest rows or columns inside of rows or columns. The left column's widget tree nests rows and columns.


2 Answers

There is no Widget similar to ConstraintLayout but you can achieve what you want using different widgets, like this example:

  class Testing2 extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Container(
        color: Colors.red,
        child: Row(
          children: <Widget>[
            Flexible(
              child: Column(
                children: <Widget>[
                  Flexible(
                    flex: 1,
                    child: Container(
                      color: Colors.deepOrange,
                    ),
                  ),
                  Flexible(
                    flex: 2,
                    child: Container(
                      color: Colors.lightBlue,
                    ),
                  ),
                ],
              ),
            ),
            Flexible(
              child: Column(
                children: <Widget>[
                  Flexible(
                      flex: 3,
                      child: Container(
                        color: Colors.orange,
                      )),
                  Flexible(
                    flex: 1,
                    child: Row(
                      children: <Widget>[
                        Flexible(
                            flex: 2,
                            child: Container(
                              color: Colors.blue,
                            )),
                        Flexible(child: Container(color: Colors.green))
                      ],
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      );
    }

Result

Also you can take a look this link to know about Layout Widgets: https://flutter.io/widgets/layout/

like image 143
diegoveloper Avatar answered Oct 11 '22 11:10

diegoveloper


You can try this:

https://github.com/hackware1993/Flutter-ConstraintLayout

Build flexible layouts with constraints, Similar to Android ConstraintLayout.

No matter how complex the layout is and how deep the dependencies are, each child element of ConstraintLayout will only be measured once, This results in extremely high layout performance.

like image 1
陈方兵 Avatar answered Oct 11 '22 12:10

陈方兵