Mainaxis alignment.spacebetween 不是 working.flutter

Mainaxis alignment.spacebetween is not working.flutter

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 不工作。如果该行不在堆栈内,它就可以正常工作。两个按钮在行的开头相互粘在一起。我该如何解决?

只需从第一个 children 中删除 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),
        ),
      ),
    ],
  );
}

如果您没有给容器适当的宽度,那么它会根据内容考虑它的宽度。