[英]Flutter : align center a specific child in a Row Widget
I'm a newbie in flutter and I'm trying to code a UI Instagram clone, How can I align a carousel indicator to the center with a Row()
parent like this我是一个新手,我正在尝试编写 UI Instagram 克隆,如何将轮播指示器与像这样的
Row()
父级对齐到中心
Stack(
alignment: Alignment.center,
children:[
buildIndicator(),
//Icon section
Row(
children:[
buildLeftIcons(),
buildRightIcon(),
],
),
],
),
Result I got: ![final result][this]结果我得到: ![最终结果][这个]
Hey you can use Spacer() between icons and dot in row children .嘿,您可以在图标和行之间的点之间使用 Spacer() children 。 Spacer widget auto take extra width like below -
间隔小部件自动采用额外的宽度,如下所示 -
Row(
children: [
Icon(),
Icon(),
Icon(),
Spacer(),
DotsIndicator(),
Spacer(),
],
),
Here is another example with Expanded
widget and row, Expanded will automatically take rest of width other then icons这是
Expanded
小部件和行的另一个示例,扩展将自动占用除图标之外的其余宽度
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(),
Icon(),
Icon(),
Expanded(
child: Center(
child: DotsIndicator(),
)
),
],
),
// UI with left and right icons // 带有左右图标的 UI
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(),
Icon(),
Icon(),
Expanded(
child: Center(
child: DotsIndicator(),
)
),
Icon(),
],
),
For you reference - Spacer and Expanded供您参考 - Spacer和Expanded
在该行中,您可以在范围内提供一个SizedBox(width: )
以将特定小部件推送一定距离。
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
///put favourite,comment,send icon here
],
),
///put yor indicator widget here
Indicator(),
///add an empty container here
Container()
],
)
It would somehow complex to do that but I have two suggestions:这样做会有点复杂,但我有两个建议:
Row()
's MainAxisAlignment.start
then add a desired Widget in between the first widgets and the indicators to give space say like a SizedBox(width:80.0)
Row()
的MainAxisAlignment.start
然后在第一个小部件和指示器之间添加所需的小部件,以提供空间,例如SizedBox(width:80.0)
Column()
.Column()
分隔两个小部件。 I prefer this since I would just add the carousel indicator as first item in the column then wrap it in a Center()
widget, then the second widget in the column would be your desired widgets(favourite, message and comments icons)Center()
小部件中,然后列中的第二个小部件将是您想要的小部件(收藏夹、消息和评论图标)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.