如何将precacheImage()SvgPicture包中的flutter_svg: 0.17.4一起使用?

我想在后台加载svg图片


  Container _graphicSection() {
    final String graphic = 'assets/graphic/two_people.svg';
    return Container(
        child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        SvgPicture.asset(
          graphic,
          height: 150,
          alignment: Alignment.center,
        )
      ],
    ));
  }

有谁知道如何使用precachImage()函数加载svg图片?

最佳答案


Future<void> loadPictures() async {
  await precachePicture(
    ExactAssetPicture(SvgPicture.svgStringDecoder, 'assets/graphic/two_people.svg'),
    context,
  ); //here context can also be null
}

关于image - Flutter中带有SvgPicture的precacheImage,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61303605/

10-09 03:23