简体   繁体   English

在行内的小部件之间显示相等的空间 - Flutter

[英]Displaying Equal Space between Widgets inside Row - Flutter

Below is the builder method that I have created to create my Widgets in flutter app:下面是我为在 flutter 应用程序中创建小部件而创建的构建器方法:

Widget _buildParkingAndNagarSection(String title, Color colorBackground,
  double marginBox) {
return Expanded(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
          padding: EdgeInsets.only(top: 20, left: 20),
          width: 153.5.w,
          height: 114.h,
          decoration: BoxDecoration(
              color: colorBackground,
              shape: BoxShape.rectangle,
              border: Border.all(
                  color: Color(0xFFF1F1F1),
                  width: 1.h
              ),
              borderRadius: BorderRadius.all(Radius.circular(10))),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Image.asset(ic_bottom_home,
                  width: 44.w, height: 33.75.h, fit: BoxFit.fill),
              SizedBox(
                height: 20,
                width: 0,
              ),
              Text(
                title,
                style: TextStyle(
                    fontFamily: "Poppins",
                    fontSize: 14.sp,
                    color: Color(0xFF27303E)),
                softWrap: true,
                overflow: TextOverflow.fade,
              )
            ],
          ),
        )
      ],
    ));

Calling it as below inside Row:在 Row 中如下调用它:

Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          _buildParkingAndNagarSection(
              Localization
                  .of(context)
                  .labelSaveParking,
              Color(0xFFE7F8FF), 20),
          _buildParkingAndNagarSection(
              Localization
                  .of(context)
                  .labelNavigateNagar,
              Color(0xFFFFE7EB), 10),
        ],
      ),

But What I have achieved is as below:但我所取得的成就如下:

在此处输入图像描述

You can see there is little more space between Two Boxes.你可以看到两个盒子之间的空间很小。 I want them as equal as it is there it's left and right side.我希望它们在左侧和右侧一样平等。

How?如何? Thanks.谢谢。

_buildParkingAndNagarSection this method is returning an Expanded widget. _buildParkingAndNagarSection这个方法返回一个 Expanded 小部件。 So if you add 2 items in a row it will form fill up the whole space.因此,如果您连续添加 2 个项目,它将填满整个空间。 The mainAxisAlignment will have no changes because of this.因此 mainAxisAlignment 不会有任何变化。 Remove the expanded widget from it and it should space evenly as expected从中删除扩展的小部件,它应该按预期均匀分布

Here is the solution for your problem这是您的问题的解决方案

Row(
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  children: [
    ElevatedButton(
      onPressed: () {},
      child: const Text(
        'Button One',
        style: TextStyle(fontSize: 24),
      ),
    ),
    ElevatedButton(
      onPressed: () {},
      child: const Text(
        'Button Two',
        style: TextStyle(fontSize: 24),
      ),
    ),
    
  ],
)

You can use below in Row您可以在下面的行中使用

 mainAxisAlignment: MainAxisAlignment.spaceEvenly

Also, If you face any issue please check padding and margin you applied in that widgets.此外,如果您遇到任何问题,请检查您在该小部件中应用的填充和边距。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM