Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing a widget to overflow to another widget

Tags:

flutter

I was trying to achieve an effect of allowing a widget to overflow to another widget
as seen here

The code I've this far is this:

  @override
  Widget build(BuildContext context) {
    Size screenSize = MediaQuery.of(context).size;
    return new Column(children: <Widget>[
      new Container(
      color: Colors.blue,
      height: screenSize.height / 2,
      width: screenSize.width,
      child: new Center(
        child: new Container(
          margin: const EdgeInsets.only(top: 320.0),
          color: Colors.red,
          height: 40.0,
          width: 40.0,
        ),
      ))
]);
}

This resulted in the following, the square is cut off by the container.
Is there another approach to this?

like image 752
Omer Avatar asked Mar 01 '18 12:03

Omer


People also ask

How can I put a widget above another widget in Flutter?

In Flutter, the overlay lets you print visual elements on top of other widgets by inserting them into the overlay's stack. You insert a widget into the overlay using an OverlayEntry and you use Positioned and AnimatedPositioned to choose where the entry is positioned within the overlay.

How do you control overflow in Flutter?

TextOverFlow Parameters Ellipsis: Use an Ellipsis (. . .) to indicate that text is overflow. Code: Text( 'Wanted Text', overflow: TextOverflow. ellipsis, ), Fade: Overflowed Text show as Transparent.


1 Answers

Generally speaking you should never overflow in flutter.

If you want a specific layout, you'll need to explicitly separate the "overflowing" widget on a different layer.

One solution for that is Stack widget, which allow widgets to be above each others.

In the end to achieve this :

enter image description here

the flutter code would be

new Stack(
  fit: StackFit.expand,
  children: <Widget>[
    new Column(
      mainAxisSize: MainAxisSize.max,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        new Expanded(
          child: new Container(
            color: Colors.blue,
          ),
        ),
        new Expanded(
          child: new Container(
            color: Colors.white,
          ),
        ),
      ],
    ),
    new Center(
      child: new Container(
        color: Colors.red,
        height: 40.0,
        width: 40.0,
      ),
    )
  ],
);
like image 79
Rémi Rousselet Avatar answered Oct 15 '22 17:10

Rémi Rousselet