【问题标题】:How to check if screen is fully loaded?如何检查屏幕是否已满载?
【发布时间】:2022-01-08 10:41:30
【问题描述】:

问题:我的应用程序中的一个屏幕有一堆从 API 获取的网络图像。当用户导航到该屏幕时,某些图像的加载速度比其他图像快,因此用户会看到一个未完全加载的屏幕。

预期行为:我想显示CircularProgressIndicator,直到所有网络图像都完全加载。

附:下面的代码没有做我想要的,因为它在图像仍在加载时执行该函数。

void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) => yourFunction(context));
}

我也在使用来自flutter_svg 包的SvgPicture.network

【问题讨论】:

    标签: flutter flutter-layout flutter-web


    【解决方案1】:
    final Widget networkSvg = SvgPicture.network(
      'https://site-that-takes-a-while.com/image.svg',
      semanticsLabel: 'A shark?!',
      placeholderBuilder: (BuildContext context) => Container(
          padding: const EdgeInsets.all(30.0),
          child: const CircularProgressIndicator()),
    );
    

    也许这可以帮助Flutter image preload

    【讨论】:

    • 不,我想显示整个屏幕的进度指示器。对不起,如果我的问题令人困惑。我现在已经编辑了我的问题。
    • Flutter 有一个挂载事件,告诉你小部件已经完全加载。您可以在此事件上隐藏进度指示器并在 initstate 上显示它
    猜你喜欢
    • 2011-10-30
    • 2012-12-28
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-19
    • 2016-01-31
    • 1970-01-01
    相关资源
    最近更新 更多