Drawing in Flutter using CustomPainter
ฝัง
- เผยแพร่เมื่อ 23 ก.ย. 2024
- Follow us on :
instagram : / moie_studio
github : github.com/sha...
/// Code to take a pic
First you need to wrap CustomPaint widget with Repaintboundary and a key
RepaintBoundary(key:repaintKey, child CustomPaint:......
Now to take picture of what you have drawn can use this code
RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
Image image = await boundary.toImage(pixelRatio: 3.0);
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
var pngBytes = byteData.buffer.asUint8List();
var bs64 = base64Encode(pngBytes);
Now you can use base64 to generate an image or share the image
Who are You, Who are so Wise in the Ways of Flutter ? Seriously thanks for the tutorial .
Thanks a lot :) do checkout our other flutter videos also and do subscribe to our channel 😊
Good explaination! but what was the use of rxdart ? BehaviorSubject ?
The Besttt 🌸
Thank you 🤗
anyone know how to solve pointList.add(null)? The argument type 'Null' can't be assigned to the parameter type 'DrawModel'.?
This is too good man!! 👌👌
Thanks ,
My drawing canvas still starts to hang after intensive drawing even after using stream builder instead of set state.
Anyways Thanks for tutorial.
Nice
Thank you 😬 support us for more such content
What is the variable ui in the ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);?
I've imported dart.ui as ui
How to solve unimplemented error
Can we draw on PDF and then save PDF with the drawings we have done on it? If not do you know any way to do it?
I'm not sure if we can draw on a pdf, I'll look into it
You can try to use the stack widget
Basically you can render the drawing widget over the pdf view, however the pdf is not being edited directly but we can save the offset information along the widget and store it locally or on a server.
Were you able to find a solution for the problem I also wanted this feature in my app.
When I try to draw it gives me this error
════════ Exception caught by gesture ═══════════════════════════════════════════
The method 'findRenderObject' was called on null.
Receiver: null
Tried calling: findRenderObject()
═════════════════════════════════════════════════════════════════════
Could you help me please?
it is not possible assign null values a list with offsett types, it is not working with Flutter 3.0