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),
),
),
],
);
}
主轴对齐。spacebetween 不起作用。 我正在创建一个页面,但 mainaxisAlignment.spaceBetween 不起作用。如果行不在 stack 内,它工作得很好。两个按钮在行的开头相互粘在一起。我该如何解决这个问题?
答案 0 :(得分:0)
只需从第一个孩子中删除 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),
),
),
],
);
}
如果您没有为容器提供适当的宽度,则将其视为每个内容的宽度。