【问题标题】:Set Icon in left of app in all size of phone在所有手机尺寸的应用程序左侧设置图标
【发布时间】:2021-11-04 05:14:15
【问题描述】:

我想设置文本右侧(宽度 * 0.08)和图标左侧(宽度 * 0.08)但是当我运行它时。它不起作用。 并且当我为文本设置填充右侧并为图标设置左侧填充时,其他尺寸不起作用。 关于网络和电话的图像。 宽度 = 1080 .

这是我的代码的一部分:

  Container(
            child: Row(
          children: [
            Container(
              alignment: Alignment.centerRight,
              child: Padding(
                padding: EdgeInsets.only(
                    top: pageWidth * 0.08,
                    right: pageWidth * 0.09,
                    bottom: pageWidth * 0.03),
                child: Text(
                  "سلام",
                  style: TextStyle(
                      fontSize: 20),
                ),
              ),
            ),
            Container(
                child: Padding(
              padding: EdgeInsets.only(
                  top: pageWidth * 0.08,
                  left: pageWidth * 0.06,
                  bottom: pageWidth * 0.04),
              child: IconButton(
                alignment: Alignment.topLeft,
                onPressed: () {},
                icon: Container(
                  child: SvgPicture.asset(
                    homeSettings,
                    width: pageWidth * 0.062,
                    height:pageWidth * 0.062,
                  ),
                ),
              ),
            )),
          ],
        )),

【问题讨论】:

    标签: flutter dart text icons alignment


    【解决方案1】:

    您可以使用mainAxisAlignment: MainAxisAlignment.spaceBetween,

    添加const Spacer() 以在它们之间添加空格。

    或使用

     Expanded(
                  child: Align(
                    alignment: Alignment.centerRight,
                    child: Text(
                      "سلام",
                      style: TextStyle(fontSize: 20),
                    ),
                  ),
                )
    

    【讨论】:

      【解决方案2】:

      您只需要在两个容器之间添加一个Spacer 小部件,如下所示:

      Container(
              child: Row(
            children: [
              Container(
                alignment: Alignment.centerRight,
                child: Padding(
                  padding: EdgeInsets.only(
                      top: pageWidth * 0.08,
                      right: pageWidth * 0.09,
                      bottom: pageWidth * 0.03),
                  child: Text(
                    "سلام",
                    style: TextStyle(
                        fontSize: 20),
                  ),
                ),
              ),
              Spacer(),             //Add here
              Container(
                  child: Padding(
                padding: EdgeInsets.only(
                    top: pageWidth * 0.08,
                    left: pageWidth * 0.06,
                    bottom: pageWidth * 0.04),
                child: IconButton(
                  alignment: Alignment.topLeft,
                  onPressed: () {},
                  icon: Container(
                    child: SvgPicture.asset(
                      homeSettings,
                      width: pageWidth * 0.062,
                      height:pageWidth * 0.062,
                    ),
                  ),
                ),
              )),
            ],
          )),
      

      【讨论】:

        【解决方案3】:

        将行的mainAxisAlignment 属性设置为spaceBetween

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-02-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多