createPaint method
Implementation
createPaint(
GlobalKey key,
// {Alignment alignment = Alignment.center,
// Size size = const Size(double.maxFinite, double.maxFinite),
// double devicePixelRatio = 1.0,
// double pixelRatio = 1.0}
) async {
// final widgetAsRepaintBoundary = RepaintBoundary(
// child: widget,
// key: key,
// );
_boundary =
key.currentContext?.findRenderObject() as RenderRepaintBoundary?;
if (_boundary != null) {
// Ensure that the widget is actually rendered on the screen
key.currentContext?.visitChildElements((element) {
final renderObject = element.renderObject;
if (renderObject is RenderRepaintBoundary) {
// Trigger a repaint of the RenderRepaintBoundary
renderObject.markNeedsPaint();
}
});
// Wait for the next frame to ensure that the repaint is complete
await Future.delayed(const Duration(milliseconds: 200));
// Convert the widget to an image
_imageAsDartUiImage = await _boundary!.toImage(pixelRatio: 6);
}
// await toDartUiImage(boundary);
// await toByteData();
// toUint8List();
// toImage();
// try {
// RenderRepaintBoundary repaintBoundary = RenderRepaintBoundary();
// // RenderView renderView = RendererBinding.instance.renderView;
// RenderView renderView = RenderView(
// child: RenderPositionedBox(
// alignment: alignment,
// child: repaintBoundary,
// ),
// configuration: ViewConfiguration(
// size: size,
// devicePixelRatio: devicePixelRatio,
// ),
// view: RendererBinding.instance.platformDispatcher.views.first,
// );
// PipelineOwner pipelineOwner = PipelineOwner();
// pipelineOwner.rootNode = renderView;
// renderView.prepareInitialFrame();
// BuildOwner buildOwner = BuildOwner(focusManager: FocusManager());
// RenderObjectToWidgetElement rootElement = RenderObjectToWidgetAdapter(
// container: repaintBoundary,
// child: widget,
// ).attachToRenderTree(buildOwner);
// buildOwner.buildScope(rootElement);
// buildOwner.finalizeTree();
// pipelineOwner.flushLayout();
// pipelineOwner.flushCompositingBits();
// pipelineOwner.flushPaint();
// _imageAsDartUiImage =
// await repaintBoundary.toImage(pixelRatio: pixelRatio);
// } catch (e) {
// print(e);
// }
}