dnfield / flutter_svg

SVG parsing, rendering, and widget library for Flutter
MIT License
1.66k stars 455 forks source link

[Web] can't compile because of fake File #1059

Open richert-addisca opened 5 months ago

richert-addisca commented 5 months ago

When I use a dart:io File type in the same dart file as SvgPicture.file on the web, it won't compile saying the types are not compatible.

When I remove the if condition in \flutter_svg-2.0.10+1\lib\src\utilities\file.dart locally, everything compiles and works as expected.

This even happens when doing an early return for web.

if (kIsWeb) {
  return SvgPicture.network(
    imageUrl!,
  );
}

ref.watch(imageToFileProvider);
File? file = ref.watch(imageToFileProvider.notifier).getFile(imageUrl!);

if (file == null) {
  return svgPlaceholder(context);
}

return 
  (imageUrl!.contains(".svg") || file.path.endsWith('.svg'))
    ? SvgPicture.file(
      file,
    )
    : RoundedContainer(
      borderRadius: borderRadius,
        child: Image.file(
          file,
        ),
      );
GVAMDaniel commented 4 months ago

Same error here

My appFile.file seems to be the same class File but when I try to compile this error appear

Captura de pantalla 2024-05-09 a las 14 27 53

The temporary solution is to load as SvgBytesLoader

SvgBytesLoader(appFile.file!.readAsBytesSync())