How can I use svg image in a container's box decoration? Seems it only allows the png/jpg files in AssetImage(). I am trying to display two images on top of the background image set through the box decoration. I am trying to dodge the method of stack. So is there a way?
Flutter has no inbuilt support for SVG as of now..
But you can try this package -> https://pub.dev/packages/flutter_svg
final Widget svg = new SvgPicture.asset(
"assets/image.svg",
);
However, I'd recommend not using an SVG, instead convert your image to a png format
Related
I have a generated png file with a barcode, I need to save the file on the device, can I add margins on the sides to the picture so that the barcode is read correctly
One way to achieve this can be using the screenshot package (that takes a screenshot of the child widget and saves it as a .png file) to take a screenshot of the image widget inside a padding widget. Give the padding the value you want to see as a margin in the image.
Another approach can be generating that barcode in .svg format and modifying its code before saving.
Or give RepaintBoundary a try.
I have an API providing images with .icon format and I would like to display the image on my Flutter app.
you can use image widget for it like bellow
Image.asset("assets/images/home.ico"),
Image.network(
"https://api.hala-on.com/category_images/icons/1672329105.icon"),
i have write these two widgets of image in actions and see the results one is displaying the .ico image from the assets and the other is displaying the image from the link you provided.
see the results
Code for this
I'm using Flutter with pdf package. In the readme it says use printing to show pdf in app.
However, I want to draw in front of the pdf content(taking notes/make annotations). So I guess I have to draw pdf content in my CustomPaint widget to get more control to it.
I searched around and didn't found any useful experience. Please let me know it my approach is correct/reasonable and if there's any better approach.
Thanks!
I think the part of the README you're talking about is this one :
Use the printing package https://pub.dev/packages/printing for full
flutter print and share operation.
This printing package is meant for printing to a real printer.
The pdf package you're using is only meant for creating a pdf in a flutter application, not for displaying it as a widget.
What you want to achieve is to display a pdf and annote on top of it. Your approach is a correct one:
Use a CustomPainter
Add a PDF widget as its child
Paint your annotations on the foreground painter.
To display a pdf as a widget you'll need another package like advance_pdf_viewer.
Painting on the foreground painter is important because as stated in the CustomPaint class documentation:
When asked to paint, CustomPaint first asks its painter to paint on
the current canvas, then it paints its child, and then, after painting
its child, it asks its foregroundPainter to paint.
The code should look like :
PDFDocument doc = await PDFDocument.fromAsset('assets/test.pdf');
return CustomPaint(
child: PDFViewer(doc: document)),
foregroundPainter: AnnotationsPainter(),
);
Currently, I am using Image.network to render PNG/JPG and SvgPicture.network to render SVG.
However, is there a Widget that is able to detect the actual image type and automatically selects either Image.network or SvgPicture.network depending on the type?
I want to draw a text inside a path in flutter. In android, the requirement can be achieved by using canvas.drawTextOnPath(). But in flutter, I didn't find any method to draw the text inside a path.
expected output:
I have created a package to achieve this in Flutter.
Link: draw_on_path: used to draw text or pattern along the given path.
Just use
canvas.drawTextOnPath(text, path);
There is an optional parameter for TextStyle and other customization.