简体   繁体   English

Flutter - 如何正确显示合成的 SVG 图像

[英]Flutter - How to display composed SVG image correctly

I want to show a composed SVG image in flutter and I am currently using the flutter_svg library.我想在 flutter 中显示一个组合的 SVG 图像,我目前正在使用flutter_svg库。

My picture consists of different layers that can be put together using the app's GUI (creating an avatar).我的图片由不同的图层组成,可以使用应用程序的 GUI(创建头像)组合在一起。

In principle it works very well with a stack of SVGPicture s, but when loading, the problem arises that some of the SVGs are displayed a little later than others and the graphics look broken in this short time - for example, the upper body of an avatar is not loaded but the rest of the body -> the avatar has a hole in the middle...原则上,它与一堆SVGPicture一起工作得很好,但是在加载时,会出现一些问题,即一些 SVG 显示得比其他 SVG 稍晚,并且图形在很短的时间内看起来就坏了 - 例如,一个头像没有加载但是身体的rest->头像中间有个洞...

Is there a way to display a composition from SVGPictures only when all parts are loaded and can be displayed?有没有办法仅在所有部分都已加载并可以显示时才显示来自 SVGPictures 的合成? Ideally, a dummy should also be displayed for this long.理想情况下,还应该显示一个假人这么长时间。

SVGs with a lot of layers will definitely cause a bit of lag while loading, hence if you want to load them all smoothly, you can try preloading SVGs.有很多层的 SVG 加载时肯定会造成一些延迟,因此如果您想顺利加载它们,可以尝试预加载 SVG。

final svg = SvgPicture.asset('assets/vector.svg');
final svgAnother = SvgPicture.asset('assets/vector.svg');

@override
Widget build(BuildContext context) {
  return Stack(
    children:[
      svg, // Load preloaded svg smoothly
      svgAnother,
    ],
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM