Flutter 之 Placeholder (九十九)

Placeholder 占位组件

1. Placeholder

  const Placeholder({
    Key? key,
    this.color = const Color(0xFF455A64), // Blue Grey 700
    this.strokeWidth = 2.0,
    this.fallbackWidth = 400.0,
    this.fallbackHeight = 400.0,
  }) 
Placeholder 属性 介绍
color 设置占位符颜色
strokeWidth 设置画笔宽度
fallbackHeight 宽度 当占位符处于无界情况时使用的宽度
fallbackWidth 高度 当占位符处于无界情况时使用的高度

2. 实例


class MSPlaceholderRoute extends StatelessWidget {
  const MSPlaceholderRoute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("MSPlaceholderRoute")),
      body: Column(
        children: [
          SizedBox(
            height: 128,
            child: Placeholder(),
          ),
          UnconstrainedBox(
            child: Placeholder(
              color: Colors.red,
              strokeWidth: 2.0,
              fallbackWidth: 200, // 当占位符处于无界情况时使用的宽度
              fallbackHeight: 200, // 当占位符处于无界情况时使用的高度
            ),
          ),
          // 占位图
          FadeInImage(
            placeholder: AssetImage("assets/images/4.jpeg"),
            image: NetworkImage(
                "https://tva1.sinaimg.cn/large/006y8mN6gy1g7aa03bmfpj3069069mx8.jpg"),
          ),
        ],
      ),
    );
  }
}

image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容