Flutter: SVG Image in the background throws an error - flutter

I have to keep the SVG Image in the background and keep the Text in the top.
When I'm keeping the SVG Image from the Flutter_SVG Package, I got a error like this.
I/flutter (24437): Unsupported operation: Could not resolve image href: Component%206%20-%201-image.png
Picture provider: ExactAssetPicture(name: "assets/images/login_header.svg", bundle: null,
I/flutter (24437): colorFilter: ColorFilter.mode(MaterialColor(primary value: Color(0xfff44336)), BlendMode.srcIn))
I/flutter (24437): Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#32e52(), name:
I/flutter (24437): "assets/images/xxx.svg", colorFilter: ColorFilter.mode(MaterialColor(primary value:
I/flutter (24437): Color(0xfff44336)), BlendMode.srcIn))

flutter_svg package that you use does not support filter effects.Sadly this is not possible with the current version of the package.This would be possible only.
Anyway one of the hacks (Crappy workaround)
Converting shadows to bitmap(not correct solution)
Follow the issue on Github Issues. Hoping the feature will be available soon as said by the developer of the package

Need to clear the caches from SVG Image. It can be done by SVGCleaner and that's will work in our project.

Download SVG CLEANER "Download" and clean the files, then open the .SVG in a text editor and change the following:
and add
That should be enough, I have had this problem several times and only then has it been fixed.

I was able to fix this by dragging and dropping the svg files to the Figma design tool and then export all of them to get the standard error-free svg files.

Do this flutter clean && flutter pub get

Related

Flutter - how add svg image?

The following UnimplementedError was thrown in parseSvgElement:
The element is not implemented in this library.
Style elements are not supported by this library and the requested SVG may not render as intended.
If possible, ensure the SVG uses inline styles and/or attributes (which are supported), or use a preprocessing utility such as svgcleaner to inline the styles for you.
2
Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#e5679(), name: "assets/image/foodigo.svg", colorFilter: null, theme: SvgTheme(currentColor: Color(0xff000000), fontSize: 14.0, xHeight: 7.0))
Not all SVG features are supported by flutter_svg package, as stated here.
You can try to use an online tool to "clean up" your SVG file (search for "SVG clean/optimize") or you can use one of the tools suggested in the same link above (like usvg).
I would suggest usvg if you have a lot of files to process.
You can also use flutter svg provider package for that : https://pub.dev/packages/flutter_svg_provider

How to use image_cropper in flutter web?

It's said in the description of the package that is supports web. But since it's not possible to get path of the file in flutter web I can't to use it. Because the only way to work with this package is to provide path of the image
I looked at the example and you have to use Image.network instead of Image.file on web.
Then you can pass in the url to the image like this:
Image.network(
url,
);
if you what to crop image than check out crop_image package

How to use SVG in Flutter

I'm currently in the process of integrating a map into my app, which should highlight individual components in color. I use this map (https://simplemaps.com/resources/svg-de), which is already available in a well-designed SVG file. I am now trying to color the individual SVG paths using Flutter Code. I am building on the svg_path_parser package (https://pub.dev/packages/svg_path_parser) and have used the corresponding example. But I am unable to replace the paths from the example with those from my SVG file. This may be due to the fact that my SVG paths are significantly longer than the ones given in the example.
I would be very grateful if you would give me a little help or a suggestion for a better approach.
step 1.add dependency in your pubspec.yaml
dependencies:
flutter_svg: any
step 2.import the flutter svg package in your app
import 'package:flutter_svg/flutter_svg.dart';
step 3. just use like below
SvgPicture.asset(
'assets/images/bm-icon1.svg',
width: 18.0,
height: 18.0,
),

SVG in Flutter Exception caught by SVG

I am using the latest library update
dependencies:
flutter_svg: ^0.17.4
Container( height: 150, //color: Colors.blue, width: screenWidth * 0.80, child: SvgPicture.asset( "assets/logo-violeta-NVIAME-login.svg", color: Color(0xFF6327f8), ), ),
------------------------------------------------------------------------
My code worked but I did Hot Restart .. and well I get the following exception
The <style> element is not implemented in this library.
Style elements are not supported by this library and the requested SVG may not render as intended.
If possible, ensure the SVG uses inline styles and/or attributes (which are supported), or use a preprocessing utility such as svgcleaner to inline the styles for you.
Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#60537(), name: "assets/logo-violeta-NVIAME-login.svg", colorFilter: ColorFilter.mode(Color(0xff6327f8), BlendMode.srcIn))
════════════════════════════════════════════════════════════════════════════════
I/flutter (26058): unhandled element metadata; Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#60537(), name: "assets/logo-violeta-NVIAME-login.svg", colorFilter: ColorFilter.mode(Color(0xff6327f8), BlendMode.srcIn))
It is actually the SVG image that you've used.
As mentioned in the error:
The <style> element is not implemented in this library.
Style elements are not supported by this library and the requested SVG may not render as intended.
If possible, ensure the SVG uses inline styles and/or attributes (which are supported), or use a preprocessing utility such as svgcleaner to inline the styles for you.
flutter_svg package does not support svg with internal css like:
<style>
.....
</style>
Here is an open GitHub issue that indicates it is not yet supported.
Some of the options that you can actually try:
Remove the internal css and write inline css
Use different svg picture
Use a preprocessing utility such as svgcleaner to inline the styles for you. Which is exactly the one you've found as mentioned in the comments. See also this SO post.
Use this tool https://jakearchibald.github.io/svgomg/
But the easiest way is to have your design tool not use CSS if possible.
My workaround: drag and drop the svg files to the Figma design tool and then export all of them to get the standard error-free svg files.
I faced this issue too, then I used 'SVG Cleaner' app to clean and inline SVG code.
By the end it worked properly ^_*

How to deal with different icon sizes

When developing for iphone, in Xcode/Swift there is an asset file where you add all the icons your application will use with 1, 2 and 3x sizes. There is probably a similar thing with Android that I don't know yet.
When developing for Flutter:
How do you deal with the different screen resolutions to use the right icon sizes?
If similar to Xcode/Swift, where do you put those files and how do you get them? What about Android?
If you know a tutorial or web page, just let me know! The only ones that I found are only dedicated for app icon and launch screen.
Thanks
Just check the official documentation about resolution-aware-image.
This is based on the device pixel ratio.
Here you have an example about the structure of your files.
.../pubspec.yaml
.../icons/heart.png
.../icons/1.5x/heart.png
.../icons/2.0x/heart.png
And this is how you have to declare the assets files into your pubspec.file
flutter:
assets:
- icons/heart.png
This is the link: https://flutter.io/docs/development/ui/assets-and-images#declaring-resolution-aware-image-assets
To add to #diegoveloper answer.
Some plugins like google-maps do not honour this standard and require you to call BitmapDescriptor.fromAsset('icons/heart.png') which is not converted to the correct image. In this case you can get the correct image from AssetImage by first createLocalImageConfiguration using the BuildContext as defined here. Then use this configuration to resolve the correct image as follows:
ImageConfiguration config = createLocalImageConfiguration(context);
AssetImage('icons/heart.png')
.obtainKey(config)
.then((resolvedImage) {
print('Name: ' + resolvedImage.onValue.name);
});
In summary
Create an asset folder with the naming convention:
pathtoimages/image.png
pathtoimages/Mx/image.png
pathtoimages/Nx/image.png
pathtoimages/etc.
Where M and N are resolutions (2.0x) or themes (dark).
Then add the image or all the images to the pubspec.file as either
flutter:
assets:
- pathtoimages/image.png
or
flutter:
assets:
- pathtoimages/
Load the images in using either AssetImage('pathtoimages/image.png') or resolving to the actual file name as mentioned above, depending on the library being used.