'How to get width and height of a CustomPaint
I am trying to make this view with CustomPainter and GestureDetector onPan, So it is a normal Scribble Screen.
GestureDetector(
onPanStart: onPanStart,
onPanUpdate: onPanUpdate,
onPanEnd: onPanEnd,
child: RepaintBoundary(
child: Container(
color: Colors.transparent,
alignment: Alignment.topLeft,
child: StreamBuilder<DrawnLine>(
stream: currentLineStreamController.stream,
builder: (context, snapshot) {
return CustomPaint(
painter: Sketcher(
normalise: false,
lines: [snapshot.data],
color: Colors.black,
strokeWidth: 5.0),
);
},
),
),
),
)
void onPanUpdate(DragUpdateDetails details) {
if (!checkBounds(context.size.topLeft(details.localPosition))) return;
RenderBox box = context.findRenderObject();
Offset point = box.globalToLocal(details.globalPosition);
List<Offset> path = List.from(line.path)..add(point);
line = DrawnLine(path: path);
currentLineStreamController.add(line);
}
Problem is that i need to bring this scribble paint to another screen as a draggable widget with keeping its shape and dimension.
I am getting its relative offset of the line by
path.forEach((element) {
element = Offset(element.dx / size.width, element.dy / size.height);
tempPath.add(element);
});
Now i have offset which i can acurratly position the painter in given size. But I don't know how to get width and height of a drawing.
context.size gives me the whole Container dimemsions but is it possible to only get dimensions of the paint that i drew with gesturedetector?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
