1

如何使用precacheImage()fromSvgPictureflutter_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 图片吗?

4

1 回答 1

1

flutter_svg现在有一个函数被调用precachePicture(),你可以像这样使用它:

Future<void> loadPictures() async {
  await precachePicture(
    ExactAssetPicture(SvgPicture.svgStringDecoder, 'assets/graphic/two_people.svg'),
    context,
  ); //here context can also be null    
}
于 2020-06-15T08:59:34.510 回答