Flutter - how add svg image? - flutter

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

Related

Adding button in pdf made using pdf package in flutter

I am using the pdf package in flutter for generating pdf from the app. I need to add a clickable kind of thing(hyperlink, button) in pdf but the package doesn't provide any widget for that purpose. Also, the basic flutter widgets couldn't be used for generating the pdf files(restricted by the package). Is there any way to solve it?
Use the Stack widget to put any widget above the pdf ?
The problem is solved now, the pdf package provides the UrlLink for the purpose of opening a link when tapped on the page.
This is the short documentation for the same.
I did it like this-
pw.UrlLink(destination: imageUrl, child: pw.Text('LINK', style: pw.TextStyle(fontSize: size)))

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,
),

Where are inbuilt icons in flutter located (default location in flutter folder)

I want to use flutter inbuilt icons as assets. So I want default location where all of flutter icons are located in flutter folder of flutter installation.
This would seem to imply that there's a fontFamily named 'MaterialIcons'. Not sure you can get it easily from any part of the Flutter distro, but https://material.io/resources/icons/ will show how to download or reference the font for your material designs.
static const IconData ac_unit_outlined = IconData(0xe005, fontFamily: 'MaterialIcons')
I don't think they are. If you look at the IconData class (https://api.flutter.dev/flutter/widgets/IconData-class.html). You will see that the description says 'A description of an icon fulfilled by a font glyph.'
Taking an example of one of the Icon values:
static const IconData list_alt = IconData(0xe81b, fontFamily: 'MaterialIcons');
I believe what that is telling us is that the Icon is being defined by the position 0xe81b in the Unicode font family called MaterialIcons
Not an answer to the original question, but likely tangentially helpful...
To visually identify & search/filter icons, both from the included MaterialIcons from Google and those created by the Community, check out:
https://materialdesignicons.com/
And to use them, the related pub.dev package for material_design_icons_flutter.

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 ^_*

Flutter: SVG Image in the background throws an error

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