loadPicture method

Future<PictureInfo> loadPicture(
  1. BytesLoader loader,
  2. BuildContext? context, {
  3. bool clipViewbox = true,
  4. VectorGraphicsErrorListener? onError,
})

Load the PictureInfo from a given loader.

It is the caller's responsibility to handle disposing the picture when they are done with it.

Implementation

Future<PictureInfo> loadPicture(
  BytesLoader loader,
  BuildContext? context, {
  bool clipViewbox = true,
  VectorGraphicsErrorListener? onError,
}) async {
  TextDirection textDirection = TextDirection.ltr;
  Locale locale = ui.PlatformDispatcher.instance.locale;
  if (context != null) {
    locale = Localizations.maybeLocaleOf(context) ?? locale;
    textDirection = Directionality.maybeOf(context) ?? textDirection;
  }
  return loader.loadBytes(context).then((ByteData data) {
    try {
      return decodeVectorGraphics(
        data,
        locale: locale,
        textDirection: textDirection,
        loader: loader,
        clipViewbox: clipViewbox,
        onError: onError,
      );
    } catch (e) {
      debugPrint('Failed to decode $loader');
      rethrow;
    }
  });
}