【问题标题】:Mainaxis alignment.spacebetween is not working.flutter主轴对齐。空间之间不工作。颤振
【发布时间】:2021-08-12 15:00:39
【问题描述】:
Widget stack(BuildContext context, image, title, subtitle, height) {
  return Stack(
    clipBehavior: Clip.none,
    children: [
      Positioned(
        top: createSize(57, context, fromHeight: true),
              child: Container(
                
                child: Row(
                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            IconButton(
                icon: Icon(Icons.arrow_back),
                onPressed:(){},
            ),SizedBox(width: createSize(300, context),),
            Text('Skip'),
          ],
        ),
              ),
      ),
      Positioned(
        left: createSize(16, context),
        top: createSize(109, context, fromHeight: true),
        // height: createSize(height, context),
        // width: createSize(width, context),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(
                  fontSize: createSize(22, context),
                  color: Colors.black,
                  fontWeight: FontWeight.w600),
            ),
            Text(
              subtitle,
              style: TextStyle(
                  color: Color.fromRGBO(159, 159, 159, 1),
                  fontSize: createSize(12, context)),
            ),
          ],
        ),
      ),
      Container(
        height: height,
        width: createSize(375, context),
        decoration: BoxDecoration(
          image: DecorationImage(image: AssetImage(image), fit: BoxFit.cover),
        ),
      ),
    ],
  );
}

主轴alignment.spacebetween 不起作用。 我正在创建一个页面,但 mainaxisAlignment.spaceBetween 不起作用。如果该行不在堆栈内,它就可以正常工作。两个按钮在行的开头都相互粘着。我该如何解决这个问题?

【问题讨论】:

    标签: flutter stack


    【解决方案1】:

    只需从第一个孩子中删除 Positioned 并将设备宽度作为容器的宽度

    这是您的更新代码

    Widget stack(BuildContext context, image, title, subtitle, height) {
      return Stack(
        clipBehavior: Clip.none,
        children: [
       Container(
          width: MediaQuery.of(context).size.width, 
          child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                IconButton(
                    icon: Icon(Icons.arrow_back),
                    onPressed:(){},
                ),SizedBox(width: createSize(300, context),),
                Text('Skip'),
              ],
            ),
          ),
         
          Positioned(
            left: createSize(16, context),
            top: createSize(109, context, fromHeight: true),
            // height: createSize(height, context),
            // width: createSize(width, context),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: TextStyle(
                      fontSize: createSize(22, context),
                      color: Colors.black,
                      fontWeight: FontWeight.w600),
                ),
                Text(
                  subtitle,
                  style: TextStyle(
                      color: Color.fromRGBO(159, 159, 159, 1),
                      fontSize: createSize(12, context)),
                ),
              ],
            ),
          ),
          Container(
            height: height,
            width: createSize(375, context),
            decoration: BoxDecoration(
              image: DecorationImage(image: AssetImage(image), fit: BoxFit.cover),
            ),
          ),
        ],
      );
    }
    

    如果你没有给容器一个合适的宽度,那么它会根据内容来考虑它的宽度。

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 2020-05-04
      • 2018-11-11
      • 2019-05-05
      • 2020-09-01
      • 1970-01-01
      • 2021-11-02
      • 2020-05-04
      • 2021-07-07
      相关资源
      最近更新 更多