首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >主轴alignment.spacebetween不是working.flutter

主轴alignment.spacebetween不是working.flutter
EN

Stack Overflow用户
提问于 2021-05-24 17:39:45
回答 1查看 22关注 0票数 0
代码语言:javascript
复制
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),
        ),
      ),
    ],
  );
}

Mainaxis alignment.spacebetween不工作。我正在创建一个页面,但是mainaxisAlignment.spaceBetween不工作。如果行不在堆栈.Both中,它就可以正常工作。在行的开头,按钮彼此粘合在一起。我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-24 17:53:17

只需从第一个子对象中移除Positioned,并将设备宽度作为容器的宽度

这是您更新的代码

代码语言:javascript
复制
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),
        ),
      ),
    ],
  );
}

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67669810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档