Does Flutter support negative margin?

前端 未结 8 736
你的背包
你的背包 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:06

    You can use OverflowBox to disregard certain constraints.

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: SafeArea(
            child: Container(
              color: Colors.blue.shade300,
              child: Padding(
                padding: const EdgeInsets.all(20),
                child: Column(
                  children: [
                    Expanded(
                      child: Container(
                        color: Colors.white,
                        child: Center(
                          child: Text('Padding on this one.'),
                        ),
                      ),
                    ),
                    SizedBox(height: 20),
                    Expanded(
                      child: OverflowBox(
                        maxWidth: MediaQuery.of(context).size.width,
                        child: Container(
                          color: Colors.red.shade300,
                          child: Center(
                            child: Text('No padding on this one!'),
                          ),
                        ),
                      ),
                    ),
                    SizedBox(height: 20),
                    Expanded(
                      child: Container(
                        color: Colors.yellow.shade300,
                        child: Center(
                          child: Text('Look, padding is back!'),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        );
      }
    

    Result:

提交回复
热议问题