我为背景创建了一个 SVG 图像,但它会在一段时间后加载,问题是: 当它还没有加载时,所有的小部件都会随机出现。图像加载后,我只需要一个加载器,页面小部件出现。 代码是:
Scaffold(
appBar: const _CustomNotificationAppBar(),
body: isFinished
? SingleChildScrollView(
child: Stack(
children: [
//notification background
Opacity(
opacity: 0.42,
child: SvgPicture.asset(
'assets/images/notification_background.svg',
),
),
IconButton(
icon: const Icon(
Icons.notifications_active_outlined,
),
onPressed: () {})),
],
),
)
: const Center(
child: CircularProgressIndicator(),
),
);
最佳答案
好吧,如果我很了解你,只要你的 SVG 是从设备“ Assets ”加载的, 首先不应该有延迟。
我认为问题是你的模拟器或物理设备太慢了,你可能只在调试中遇到这个问题
尝试运行 flutter build APK 并将生成的 APK 安装到您的手机中,然后检查问题是否仍然存在。
不过你也可以这样实现
SvgPicture.asset(
'assets/images/notification_background.svg',
placeholderBuilder: (context) => Text("I am Loading"),
),
关于flutter - 在 SVG 图像加载之前加载图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67195151/