You are using the size of the screen as the size of the InteractiveViewer content. Try wrapping the Interactive viewer with a LayoutBuilder and setting those constraints to the CustomPainter size.
Also make sure you render the paint correctly respecting the given bounds