david2020
david2020

Reputation: 479

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

Upvotes: 21

Views: 15860

Answers (2)

陈方兵
陈方兵

Reputation: 21

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.

Upvotes: 2

diegoveloper
diegoveloper

Reputation: 103541

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/

Upvotes: 8

Related Questions