[英]Which widgets should be used for responsive UI of the following wireframe?
Row
with spaceEvenly
用Row
spaceEvenly
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//your images
],
);
https://flutteragency.com/how-to-set-space-between-elements-in-flutter/ https://flutteragency.com/how-to-set-space-between-elements-in-flutter/
There are many ways to do this.有很多方法可以做到这一点。 It will also depend on what responsive behavior you are looking for.它还取决于您正在寻找的响应行为。 I hope, I understood your specific requirements.我希望,我了解您的具体要求。
Here is a solution:这是一个解决方案:
class Page extends StatelessWidget {
const Page({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: AspectRatio(
aspectRatio: 16 / 9,
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/bg.png"),
fit: BoxFit.cover,
),
),
child: Stack(children: [
Center(
child: FractionallySizedBox(
widthFactor: .4,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Text(
'Headline text',
style: GoogleFonts.chewy(
textStyle: const TextStyle(
color: Colors.white,
letterSpacing: .5,
),
),
),
),
),
),
Container(
alignment: const Alignment(0, .75),
child: FractionallySizedBox(
widthFactor: .8,
heightFactor: .3,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/images/img1.png"),
Image.asset("assets/images/img2.png"),
Image.asset("assets/images/img3.png"),
],
),
),
)
]),
),
),
);
}
}
In this solution,在这个解决方案中,
Container
that will have your image as background.我使用一个主Container
,它将您的图像作为背景。Stack
to position the headline and the images.然后我使用一个Stack
来 position 标题和图像。Center
ed and defined as a FittedBox
inside a FractionallySizedBox
.标题是Center
ed,并定义为FractionallySizedBox
内的FittedBox
。 This allows me to have responsivity for the headline too.这也让我对标题也有责任感。FractionallySizedBox
to size the list and an aligned Container
to position it within the stack.最后,对于图像列表,我使用了FractionallySizedBox
来调整列表的大小,并在堆栈中使用对齐的Container
到 position 它。 The images are then spread thanks to the use of MainAxisAlignment.spaceBetween
.然后通过使用MainAxisAlignment.spaceBetween
传播图像。So, as you see, I used the following widgets to responsively size and position my Widgets:因此,如您所见,我使用以下小部件来响应大小和 position 我的小部件:
Center
Container
with the alignment
property具有alignment
属性的Container
FractionallySizedBox
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.