Does Flutter support negative margin?

前端 未结 8 719
你的背包
你的背包 2020-12-15 02:34

Negative margin is generally not needed but there are situations where it’s really useful. For example: why use negative margins?

For now, when I set margin for a co

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 03:09

    I'm gonna give an answer for this, mostly because I had to find a way to do this.

    I would like to say that it is not ideal and could likely be accomplished in a better way, but it does give the desired effect.

    As you can see, the text can be pulled negatively outside its parent using a stack:

    Container(
      constraints: BoxConstraints.loose(Size.fromHeight(60.0)),
      decoration: BoxDecoration(color: Colors.black), 
      child: 
        Stack(
          alignment: Alignment.topCenter,
          overflow: Overflow.visible,
          children: [
            Positioned(
              top: 10.0,
              left: -15.0,
              right: -15.0,
              child: Text("OUTSIDE CONTAINER", style: TextStyle(color: Colors.red, fontSize: 24.0),)
            )
          ]
        )
    )
    

提交回复
热议问题