【占位 widget】 Flutter Placeholder

1,056 阅读1分钟

Placeholder widget 绘制一个框,表示将来将添加其他小部件的位置。Placeholder 在开发过程中非常有用,可以指示界面尚未完成。

Placeholder 介绍

默认情况下,占位符的大小适合其容器。如果占位符位于 unbounded space,它将根据给定的 fallbackWidth 和 fallbackHeight 调整自身大小。

Placeholder 可以用最快的速度搭建起页面的骨架,把流程跑起来,然后一步一步完善其中的内容。Placeholder 可以指定 color, strokeWidth,fallbackHeight 和 fallbackWidth。

使用 Placeholer

 SizedBox(width:100,height:100,child: Placeholder(
      color: Colors.green,
      strokeWidth: 10,
    ));

就是这个样子了,color 是线条的颜色。

如果用在 Row ,Column 里面,默认在宽度,高度是 unbounded,可以用 fallbackHeight 和 fallbackWidth 限定大小。

SizedBox(
        height: 100,
        child: Row(
          children: [
            Placeholder(
              fallbackWidth: 100,
              color: Colors.green,
              strokeWidth: 10,
            )
          ],
     ));
SizedBox(
        width: 100,
        child:Column(
          children: [
            Placeholder(
              fallbackHeight: 100,
              color: Colors.green,
              strokeWidth: 10,
            )
          ],
     ));

今天就到这里了,谢谢观看。