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中,它就可以正常工作。在行的开头,按钮彼此粘合在一起。我该如何解决这个问题呢?
发布于 2021-05-24 17:53:17
只需从第一个子对象中移除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),
),
),
],
);
}如果你没有给容器一个合适的宽度,那么它就是根据内容考虑它的宽度。
https://stackoverflow.com/questions/67669810
复制相似问题