【问题标题】:how to add margin in multiple Container at one time in flutter如何在颤动中一次在多个容器中添加边距
【发布时间】:2023-01-31 00:33:58
【问题描述】:

如何一次在两个或多个容器中添加边距 image

child: Expanded(
                child: Padding(
                  padding: const EdgeInsets.only(top: 100,bottom: 100),
                  child: Row(
                    children: [
                      Expanded(
                        child: Container(
                          margin: new EdgeInsets.all(10),
                          decoration: BoxDecoration(color: Colors.blueAccent),
                        ),
                      ),
                       Expanded(
                         child: Container(
                           decoration: BoxDecoration(color: Colors.amber),
                         ),
                       ),

如何一次在多个容器中添加边距或容器在边距冷藏时翘曲

【问题讨论】:

  • 你能解释一下你的问题吗我没听懂

标签: flutter margin


【解决方案1】:

为此,您必须像这样创建一个单独的可重用小部件:

class ReusableContainer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(10),
      decoration: const BoxDecoration(color: Colors.blueAccent),
    );
  }
}

然后像这样使用 ReusableContainer 小部件:

Padding(
  padding: const EdgeInsets.only(top: 100, bottom: 100),
  child: Row(
    children: [
      Expanded(
        child: ReusableContainer(),
      ),
      Expanded(
        child: ReusableContainer(),
      ),
    ],
  ),
),

【讨论】:

    猜你喜欢
    • 2022-08-04
    • 2015-12-25
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 2021-11-30
    • 2023-03-21
    • 2020-01-26
    • 1970-01-01
    相关资源
    最近更新 更多