sharjeelyunus/github-issues-dataset huggingface dataset:
Repository: flutter
Issue: [flutter_svg] Improve caching
Labels: package,team-engine,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/21_

Original report by @dnfield on Jun 12, 2018

- [ ] Make caching depend on picture size rather than number of pictures; depends on flutter/engine#5378
- [ ] Make caching strategy injectable/swappable

---
Comment by @ravenblackx on Sep 11, 2020
I would suggest that there's an inherent issue with the assumptions of the implementation of SvgPicture's cache - it's optimized for an svg that doesn't expect to change, such that if we do a fade animation on an svg, it reloads the asset for every frame of the animation, and caches the output of the newly colored render. What we usually want is for the base image to be loaded and cached, and then for each render apply the color tint. (We rarely move an svg, and frequently color-fade them.)

Optionally it could cache both the base image and the tinted image, but caching only the part we don't reuse, and reloading and rerendering from scratch for every color-frame is a really weird behavior that won't be great for performance.

There are four layers it could cache at:

1. cache the loaded data, so we only load once. There is ~never a need to invalidate this (maybe if it came from network such that the file might change).
2. cache some kind of pre-parsed loaded data, the `Picture`, in Dart terms. There is never a need to invalidate this, but I'm not sure if there's an appropriate storage structure for it because it's not using a `Picture`. Maybe the `DrawableRoot`?
3. cache the rendered base image. This is invalidated if we change size.
4. cache the rendered colored image. This is invalidated if we change size or color.

I believe the SvgPicture implementation uses option 4, and only option 4, so if we animate fading between color values then for each frame we reload, reparse, rerender, reapply the tint, cache that image, and finally paint it onto the display one time.

(I haven't dug into it super deeply; the reason I believe option 4 is what's happening is that in a unit test, if you change the color of an svg you have to waitForPendingImages to get a subsequent screenshot to show the updated color, which implies that some out-of-process operation is happening. We can get the same effect by wrapping an uncolored svg in a ColorFiltered widget, which allows for animating the color without waitForPendingImages, which is approximately equivalent to using caching option 3.)

---
Comment by @dnfield on Sep 11, 2020
You're right that there are a bunch of problems here, but you might want to consider just using a `ColorFilter` widget around the `SvgPicture` rather than providing a color/color filter parameter to the SVG.
Repository: flutter
Issue: [flutter_svg] File manipulation (tinting one group in the SVG)
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/79_

Original report by @ChristianKleineidam on Nov 11, 2018

The use case lists says: "Your vector drawing is meant to be static and non (or maybe minimally) interactive."

I have an `svg` with multiple groups (`<g>` elements) and want to be able to tint one of those at runtime either red or green. 
Is this currently possible with this library? If it isn't is such functionality out of scope or might it be developed in the future (or eventually pull requests for it accepted)?

---
Comment by @dnfield on Nov 11, 2018
This is not currently supported.  

I'd be open to options around this, but wouldn't want to compromise performance or memory usage for it.

---
Comment by @cornwe19 on Dec 19, 2018
@ChristianKleineidam This is technically possible if you drop down a level and use a `CustomPainter` to draw the layers of the SVG individually. Check out `Drawable.draw(Canvas, ColorFilter)`

@dnfield that said, it would be really helpful to cache IDs provided for each `Drawable` in the drawable itself. The current system of only being able to look them up inside a `DrawableRoot`'s definitions makes it hard to enumerate the IDs of layers present in an SVG.

Would you be open to a PR to expose IDs on `Drawable`s?

---
Comment by @dnfield on Dec 19, 2018
Yes, that sounds entirely reasonable to me.  Something like a `final String id`? And we could presumably implement `hashCode` and `operator ==` via that?

---
Comment by @cornwe19 on Dec 19, 2018
Yeah, that would be ideal. For elements with no `id` defined we could fall back on the default instance equality the Drawables currently use.

---
Comment by @yuridiniz on Apr 9, 2019
I have the same need, the only option I found is with `mergeStyle`, but it does not work very well when you have several `<g>` in your svg. Are you planning to change the style by `id`?
Repository: flutter
Issue: [flutter_svg] flutter_svg throws an xml dependency runtime error
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/106_

Original report by @minimih on Jan 25, 2019

I encountered a runtime error after a did a clean build (`flutter clean`).

The XML dependency has some breaking changes in v3.3.0 with v3.2.5 it's working.
As a workaround i defined the xml dependency in my project pubspec.yaml manually (`xml: 3.2.5`)

Possible solution is to change the flutter_svg pubspec.yaml to use `xml: 3.2.5` instead of `xml: ^3.2.5`

---
Comment by @dnfield on Jan 25, 2019
I can do that.  I thought the caret would have not applied to that kind of bump though :(

---
Comment by @minimih on Jan 25, 2019
in node.js the carret matches any `3.x.x` releases. The tilde matches any 3.2.x releases. But i don't know if flutter/dart implements it the same.

---
Comment by @dnfield on Jan 25, 2019
Fixed in 0.10.3

I'll be updating this to use the new API in the XML package at some point.
Repository: flutter
Issue: [flutter_svg] Add benchmarks
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/179_

Original report by @Vardiak on Jun 18, 2019

I think it could interesting to include benchmarks of this package in comparaison with Chrome rendering engine running on a similar device.

---
Comment by @dnfield on Jun 20, 2019
Benchmarks would be great.  I don't have a ton of time for that at the moment unfortunately, but would be happy to accept PRs.  Otherwise I'll try to get to it eventually.

Really, they'd be best so we could measure improvements int he code and what impact they're having on compute/memory usage.
Repository: flutter
Issue: [flutter_svg] Document svg-convert as a solution for cleaning up svgs
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/197_

Original report by @bsutton on Jul 19, 2019

I note in the readme you mention a couple of tools (scour, usvg) as options to clean up svg files.

We had a no. of svg files that contained css and the above tools were no help if resolving the issue.

We found the npm package svg-convert fixed the files. I thought it might be worth updating the readme to mention this tool:

[svg-style-converter](https://www.npmjs.com/package/svg-style-converter)

To install the tool:
sudo apt install npm
sudo npm i svg-style-converter -g

To run the tool
svg-convert <inputfile> <outputfile>




---
Comment by @dnfield on Jul 19, 2019
Sounds good, would you mind opening a PR with changes to the readme?

---
Comment by @misterfourtytwo on Nov 18, 2020
package with this name is not found on npm anymore
Repository: flutter
Issue: [flutter_svg] Support deleting a specific cache entry by key
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/201_

Original report by @jlcool on Jul 27, 2019

How to Delete Cache

---
Comment by @jlcool on Jul 27, 2019
FilePicture Operator in SvgPicture. File Support File Size Judgment

``` dart
file?.lengthSync() == typedOther.file?.lengthSync
```



---
Comment by @jlcool on Jul 27, 2019
Because I changed the svg, but the picture path has not changed. I hope the plug-in can make some changes. Thank you.
This is machine translation. I hope you can understand it.

---
Comment by @dnfield on Jul 27, 2019
It looks like there's nothing publically exposed to clear the cache.  

I've added `PictureProvider.clearCache()`.  There's one other thing I want to land now before I publish, but should publish a new version soon.

---
Comment by @jlcool on Jul 28, 2019
I don't know if I understand what you mean. I hope there is a way to delete the cache according to the key. See if this can be used https://api.flutter.dev/flutter/painting/ImageCache/evict.html。Let's also deal with this problem ->SvgPicture. File，Looking forward to the next version 

---
Comment by @jlcool on Jul 28, 2019
`
PictureProvider.clearCache()
` can help me, thank you.

---
Comment by @GeylanKalafMohe on May 10, 2023
We can use this code to clear all cache from the `flutter_svg: ^2.0.4`:

```
import 'package:flutter_svg/flutter_svg.dart;

svg.cache.clear();
```
Repository: flutter
Issue: [flutter_svg] Confusing Exception message while precaching Picture with wrong Asset name
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/215_

Original report by @feinstein on Aug 14, 2019

I want to pre-cache a `Picture` so it won't blink in place once I navigate to the screen that shows this `Picture`, so I just pre-cache it before navigating.

I used the following (wrong) code (pre-caching a big Image and some SVGs):

```dart
await precacheImage(Image.asset('assets/b&w.png').image, context);
await precachePicture(SvgPicture.asset('assets/b&w.png').pictureProvider, context);
```

While copy&pasting I forgot to change the name of the asset to `assets/logo.svg` and I got this error:

>Exception: FormatException: Bad UTF-8 encoding 0x89 (at offset 0)

at this line:

```dart
final String data = await key.bundle.loadString(key.name);
```

Where `key.name` was `assets/b&w.png`.

The error was pretty cryptic but I eventually figured out. I am just opening this issue because I think the error message could indicate better what went wrong, like `Asset is not an SVG`.


---
Comment by @dnfield on Aug 14, 2019
This is a good idea - we could just catch the FormatException and rethrow one that indicates this may not be an SVG.  Does that sound right to you?

---
Comment by @feinstein on Aug 14, 2019
I think its perfect.
Repository: flutter
Issue: [flutter_svg] <font> tag not supported
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/222_

Original report by @ridz0n3 on Sep 13, 2019

Hi, 

I try to put svg img that contain text, but it like render not properly in app..
this in img viewer in android studio, it should look like this:
<img width="337" alt="Screenshot 2019-09-13 at 9 07 10 PM" src="https://user-images.githubusercontent.com/8773669/64865076-1abdc580-d66b-11e9-9469-e00d8ce5c29a.png">

and this when i run in app:
<img width="464" alt="Screenshot 2019-09-13 at 9 10 06 PM" src="https://user-images.githubusercontent.com/8773669/64865139-404acf00-d66b-11e9-8327-3b920d271a74.png">

the font that i use is `PT Sans Narrow`, i also add this font in my project.

and this is the original img:
https://github.com/ridz0n3/Animation/blob/master/magCover.svg

can u help me @dnfield ?

thanks


---
Comment by @dnfield on Sep 13, 2019
At first glance, this is using letter spacing properties, which aren't supported.  I'd be happy to review.a PR that adds them.

At the end of the day though, you'll probably only get full fidelity by rendering all the glyphs as paths into the SVG.  Text is hard to get right in a cross platform way 

---
Comment by @ridz0n3 on Sep 17, 2019
> At first glance, this is using letter spacing properties, which aren't supported. I'd be happy to review.a PR that adds them.
> 
> At the end of the day though, you'll probably only get full fidelity by rendering all the glyphs as paths into the SVG. Text is hard to get right in a cross platform way

@dnfield i already remove letter spacing properties..but the font still not changing....is it `<glyphs>, <font>, <font-face>, <defs>` tags support?

---
Comment by @dnfield on Sep 17, 2019
Yes, glyphs aren't supported yet

---
Comment by @ridz0n3 on Sep 17, 2019
> Yes, glyphs aren't supported yet

@dnfield so how to do it? is it to convert all text into vector?


---
Comment by @dnfield on Sep 17, 2019
Ahh I missed this earlier - the whole `font` tag isn't supported right now.

You could either render the text into paths (I think Inkscape has an option for that), or you could create a regular (e.g. TTF) font from the font data and include it in your assets.

---
Comment by @ridz0n3 on Sep 19, 2019
alrite...thanks.
Repository: flutter
Issue: [flutter_svg] Incorrect image size when setting both width and height in conjunction with BoxFit.contain
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/229_

Original report by @fl0cke on Sep 25, 2019

Setting both width and height in conjunction with BoxFit.contain leads to incorrect image dimensions. 

Example code:

```
SvgPicture.asset(
  'some_image.svg',
  height: 64,
  width: 64,
  fit: BoxFit.contain,
)
```

According to the documentation of [BoxFit.contain](https://api.flutter.dev/flutter/painting/BoxFit-class.html), the box should be sized as large as possible while still containing the source entirely within the target dimensions. However, if the width of some_image.svg is larger than 64 pixels, the resulting SvgPicture grows beyond its specified dimensions of 64x64.

It seems like this is caused by the following code in svg.dart:

```
double width = widget.width;
double height = widget.height;
if (width == null && height == null) {
  width = viewport.width;
  height = viewport.height;
} else if (height != null) {
  width = height / viewport.height * viewport.width; <- width is overwritten 
} else if (width != null) {
  height = width / viewport.width * viewport.height;
}
```

There should be no viewport calculations whatsoever if both width and height are given.
Repository: flutter
Issue: [flutter_svg] would love to use this lib to do a one-time migration of SVG=>Flutter
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/261_

Original report by @csells on Dec 9, 2019

For dynamic images, you want to parse what you have. However, for migration of SVG assets to Flutter, it would be great to have a way to get an intermediate representation out of your library to use to dump a Flutter widget implementation from an SVG file. From such an IR, one could easily build a CLI tool that did the work.

---
Comment by @krolaw on Feb 16, 2020
I'm looking forward to this too, as I imagine this would decrease footprint and increase rendering speed.
Repository: flutter
Issue: [flutter_svg] Invalid double 1pt
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/271_

Original report by @binoysarker on Jan 6, 2020

I just installed flutter_svg in flutter and apply this code
`
trailing: FutureBuilder(
                    future: this
                        ._worldTimeService
                        .getFlag(this.allTimeZones[index].split('/').first),
                    builder: (context, snapshot) {
                      if (snapshot.connectionState == ConnectionState.done &&
                          snapshot.data != null) {
                        return SizedBox(
                          child: SvgPicture.network(
                            snapshot.data,
                            width: 50.0,
                            height: 50.0,
                            allowDrawingOutsideViewBox: false,
                          ),
                        );
                      } else {
//                        print(snapshot.data);
                        return Text('no image');
                      }
                    }),
`
**Now my problem is that this data is in list view and it is loading some svg flags in a list view. After scrolling i get this error. Please tell me how to solve this. Thanks. **

---
Comment by @dnfield on Jan 6, 2020
Flutter_svg does not support or values.

---
Comment by @kevin4dhd on Mar 30, 2022
any solution?
Repository: flutter
Issue: [flutter_svg] Canvas docs are unclear / confusing
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/282_

Original report by @shamilovtim on Jan 28, 2020

These are the docs to make an SVG canvas compatible:

```
import 'package:flutter_svg/flutter_svg.dart';
final String rawSvg = '''<svg viewBox="...">...</svg>''';
final DrawableRoot svgRoot = await svg.fromSvgString(rawSvg, rawSvg);

// If you only want the final Picture output, just use
final Picture picture = svgRoot.toPicture();

// Otherwise, if you want to draw it to a canvas:
// Optional, but probably normally desirable: scale the canvas dimensions to
// the SVG's viewbox
svgRoot.scaleCanvasToViewBox(canvas);

// Optional, but probably normally desireable: ensure the SVG isn't rendered
// outside of the viewbox bounds
svgRoot.clipCanvasToViewBox(canvas);
svgRoot.draw(canvas, size);
```

I'm not understanding several things here. What is "rawSvg" and where is the invocation to get the svg from our `assets/file.svg`? Furthermore, when I try to render the SVG to a widget it is not an `Image` so I don't see how I can use `canvas.drawImage` to render it.

Use case: looking to get an *.svg file that I can draw to a canvas.

---
Comment by @dnfield on Jan 28, 2020
You use `svgRoot.draw` and give it the canvas.

`rawSvg` is a string here. You could load it from a file - or just use the `SvgPicture.file` or `SvgPicture.asset`.

I'd be happy to review an improvement to the docs here.

---
Comment by @shamilovtim on Jan 28, 2020
if I try to do this:

```
final String rawSvg = SvgPicture.asset('assets/egg.svg');
```

I get:  `A value of type 'SvgPicture' can't be assigned to a variable of type 'String'.`
If I try `.toString()` or `toStringDeep()` all I get is a string of  "SvgPicture" not the actual svg paths. 

I can try by reading a File as well

---
Comment by @dnfield on Jan 28, 2020
Ahh sorry, you'd want loadAsset for that.

SvgPicture is a widget you just put in the tree 

---
Comment by @shamilovtim on Jan 28, 2020
Cool, will do!

---
Comment by @emvaized on Mar 29, 2020
@dnfield 
I am sorry, could you please give a full example snippet on the discussed situation?
For example, I have an `svg` file with some path data, and how can I draw it on canvas?

I'm a bit confused with your answer, especially on what `loadAsset` is. 
And also `svgRoot.draw(canvas, size)` method gives an error to me, saying that it must accept three arguments instead of two.

Thanks.

---
Comment by @AamirVakeel on Apr 29, 2020
@dnfi

> Ahh sorry, you'd want loadAsset for that.

Can you please explain this thing?
I am trying to place an SVG over a canvas so we can draw on it but i have an svg file and 

>final String rawSvg = '''<svg viewBox="...">...</svg>''';

This line isn't working out for me as i have a file. 


---
Comment by @alectogeek on May 16, 2020
@aamirvakeel1 you should load your asset file like this: `rootBundle.loadString(assetRoute)`
Repository: flutter
Issue: [flutter_svg] How to scale an image to fill whole width?
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/291_

Original report by @wellbranding on Feb 11, 2020

I have an svg image, which has the height and width of 60 pixels. However, I would like to set it's the **width to full screen** in Flutter. How can I achieve such behaviour?
Also, can I zoom the image even more than full width? Suppose my image is 2000 pixels as SVG and I would like to see only the middle part of that image (about 600 pixels).
Again, thanks for this amazing plugin!

---
Comment by @krolaw on Feb 18, 2020
`<svg height="100%" width="100%">`

`<svg height="100%" width="100%" viewBox="700 700 600 600">`
Repository: flutter
Issue: [flutter_svg] Missing argument parentPaint
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/295_

Original report by @liyuqian on Feb 18, 2020

The doc references `parentPaint`, but there's no `parentPaint` in the entire repo other than that doc: https://github.com/dnfield/flutter_svg/search?q=parentPaint&unscoped_q=parentPaint
Repository: flutter
Issue: [flutter_svg] Support <switch> element.
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/304_

Original report by @zbolo-wd on Mar 4, 2020



---
Comment by @maniveltvl on Mar 19, 2020
Hi, Team

I am trying to load SVG raw content using `SvgPicture.string(rawSvg)` but it is not loaded. My SVG content has switch value. If I load the same SVG content in browser it is working but it is not working in this plugin. Can you please help me on this?
Repository: flutter
Issue: [flutter_svg] Regression: a shape element with no color some opacity is rendering as solid black now
Labels: package,team-engine,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/307_

Original report by @dnfield on Mar 9, 2020

E.g.

```svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 264 264">
  <rect width="264" height="264" fill="lightblue"/>
  <path d="M184.32,121.12H79.38v8H184.32Z" opacity="0.1" />
</svg>
```

No longer renders correctly after #306 

Unfortunately there was no test covering this.

/cc @pento 

---
Comment by @stact on Sep 15, 2020
@pento @dnfield it seems that it's fixed with this shared sample. 

But got some unexpected effect on this sample:
https://avataaars.io/
Repository: flutter
Issue: [flutter_svg] svg large file
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/316_

Original report by @vassilux on Mar 25, 2020

Hi alls,
I try to process a large (about 5Mo) svg file from network and application freeze.

This is link for file : https://french-riviera-tattoo-convention.com/spacecontrol/longjumeau.svg

Any idea?

---
Comment by @dnfield on Mar 25, 2020
I would generally avoid trying to decode a 5mb SVG on a mobile device. That said, this does load reasonably well in Chrome on Android, and Flutter should be able to do about as well.

I do not expect to work on this any time soon, but would be happy to review proposals ot make the parsing/rendering work better for this kind of scenario.

---
Comment by @vassilux on Mar 25, 2020
ok , thank for your answer 
My target is to use DXF files in my application  so that I tried to convert DXF to svg for little POC 
if you have any idea ?
Repository: flutter
Issue: [flutter_svg] flutter_svgCC not support centerSlice . 
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/323_

Original report by @SiNguyen0604 on Apr 1, 2020

Hi all. 
I want use properties centerSlice for image svg .
Can you add properties centerSlice to flutter_svg ?  or any similar properties use in flutter_svg . Can u help me @dnfield ?

---
Comment by @dnfield on Apr 1, 2020
This  is definitely doable, although I doubt I'll be able to get to it anytime soon.  I'm also not clear on whether it's really worth the complexity it entails.  For raster images, it helps save on disk space (you can have a small square image that scales to any size without extra disk space).  With SVG, it doesn't really save you on size so much, and it should be trivial to just scale the SVG itself (if you're scaling in both dimensions), or to just construct the right SVG for what you want with minimal extra disk space.

---
Comment by @SiNguyen0604 on Apr 6, 2020
Hi @dnfield
thank your reply .
I understand but current SVG image it scale follow image SVG . I want similar property like centerSlice . Do you support me?