My final goal is to convert Flutter mobile app to Flutter web app. I used flutter_svg in Flutter mobile app but not working in Flutter web app.
What is the alternative plugin for Flutter web?
Here is error when I run project in chrome by using flutter run -d chrome
.
The following UnimplementedError was thrown during paint():
UnimplementedError
The relevant error-causing widget was:
RawPicture
file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.17.4/lib/svg.dart:729:22
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 214:49 throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/ui/src/ui/canvas.dart 898:5 drawPicture
packages/flutter_svg/src/render_picture.dart 193:12 paint
packages/flutter/src/rendering/object.dart 2264:7 [_paintWithContext]
packages/flutter/src/rendering/object.dart 184:12 paintChild
packages/flutter/src/rendering/proxy_box.dart 131:14 paint
or How to fix this issue in flutter_svg plugin in Flutter Web?
Honestly the best solution I've found is to load the image over a network for the web. Store the asset on a CDN somewhere, get it from the CDN on the web version, and retrieve it from your assets locally on iOS/Android. On the web in debug mode, I get the following error. So I don't think Image.network supports SVG.
For now you can use Image.network
for web to render svg
like this
child: kIsWeb
? Image.network("/assets/$assetName",
width: width,
height: height,
fit: fit,
color: color,
alignment: alignment,
semanticLabel: semanticsLabel)
: SvgPicture.asset(assetName,
width: width,
height: height,
fit: fit,
color: color,
alignment: alignment,
semanticsLabel: semanticsLabel)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With