【问题标题】:Flutter Container Column is not aligning correcltyFlutter Container Column 未正确对齐
【发布时间】:2021-07-31 21:34:40
【问题描述】:

我只是想在Column 中添加几个Containers,但不知何故我无法正确对齐它们...这是我的设置:

child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              ShimmerContainer(
                height: 50,
                width: 200,
              ),
              ShimmerContainer(
                height: 50,
                width: 200,
              ),
              ShimmerContainer(
                height: 50,
                width: 200,
              )
            ],
          ),

不知何故,我的Containers 都在中心对齐。真正奇怪的是,如果我用Alignment.centerLeft all 将其中一个ShimmerContainers 包装在Align 中,其他容器也会向左对齐。我不知道为什么会这样。

这是我的ShimmerContainer

class ShimmerContainer extends StatelessWidget {
  final double? height;
  final double? width;
  final double borderRadius;

  const ShimmerContainer({
    this.height,
    this.width,
    this.borderRadius = 0,
  });

  @override
  Widget build(BuildContext context) {
    return Shimmer.fromColors(
      baseColor: Colors.grey[200]!,
      highlightColor: Colors.white,
      child: Container(
        height: height != null ? height!.scaled : null,
        width: width != null ? width!.scaled : null,
        decoration: BoxDecoration(
          color: white,
          borderRadius: BorderRadius.circular(
            borderRadius,
          ),
        ),
      ),
    );
  }
}

【问题讨论】:

  • 你能添加一张你喜欢存档的UI图片吗?
  • @YeasinSheikh 容器应该左对齐而不是居中
  • 是的,它们与您的代码保持一致。
  • 您是否检查了父列是否在开始处对齐?
  • 什么是`height!.scaled`

标签: flutter dart containers alignment


【解决方案1】:

您的代码输出 我添加了背景颜色以正确查看。

我认为你应该使用flutter clean 并再次运行。父母方面发生了其他错误。它解决了您的问题吗?

【讨论】:

  • 这真的很奇怪。父级是CustomScrollView。在我的模拟器上它居中..
  • 您在使用 MultiSliver 吗?你能添加更多关于父母的信息吗
猜你喜欢
  • 1970-01-01
  • 2022-10-17
  • 2017-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-03
  • 2013-06-19
  • 1970-01-01
相关资源
最近更新 更多