Flutter - 如何从布局填充中排除小部件(对称水平)?

问题描述 投票:0回答:1

假设所有屏幕都需要相同大小的水平填充,如上图所示,所以我制作了一个每个屏幕都需要的基本布局小部件。

class BaseLayout extends StatelessWidget {
  final Widget child;

  const BaseLayout({super.key, required this.child});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 15),
          child: SafeArea(child: child)),
    );
  }
}
class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return BaseLayout(
      child: Column(
        children: [                    
          Container( // how to make only this one take whole width of the screen unlike others?            
            decoration: const BoxDecoration(color: Color(0xffFFFF7E)),
          ),
          // the below Rows need to take the padding and it does due to the BaseLayout
          Row(),
          Row()
        ],
      ),
    );
  }
}


但是,像黄色框这样的小部件必须占据屏幕的整个宽度尺寸(不需要填充)。

可能吗?或者我不应该使用该布局并将其提供给需要的人。

提前致谢。

flutter layout padding
1个回答
0
投票

您可以尝试使用负边距。

 Container(
        margin: const EdgeInsets.symmetric(horizontal: 15),
        color: Colors.blue,
        child: Text('This text will not have padding'),
      ),
© www.soinside.com 2019 - 2024. All rights reserved.