I have a situation where I am using a CustomPaint to draw some interactable elements in Flutter Web. The CustomPaint works just fine, but the GestureDetector does not adhere to the shifted left position of the CustomPaint. The first screenshot is the raw paint, as the user would see it. The CustomPaint repeats in 4 sets of 5 (Set 1, 0px left position, then increases by 20 each set, producing the gaps between sets). However, this results in the second screenshot, where the final render has almost no interactable area where it would be expected, due to a cumulative 80 pixel shift left since the GestureDetector is not wrapping the CustomPaint at the rendered coordinates. See the pictures below for a visual of the issue:
Image 1: Raw Render (No GestureDetector highlighting)
Image 2: Render with BoxDecoration overlay active showing GestureDetector interactable area
This is my first serious project in Flutter, so I'm a bit flummoxed here. I know it's down to either a misunderstanding of a component or context, that or it's a matter of me doing this in a way that won't work, but as far as I can tell looking at the Flutter docs it should work (I've read up on Containers, GestureDetector, and CustomPaint for this issue), and it's clearly not. I've tried various ways of nesting these widgets, and through that coupled with some box decoration rendering to check overlays, that's how I've narrowed this down to a matter of the GestureDetector not rendering with respect to the offset past that first set of 5 renders. The relevant code block is below (it's the return function for the widgets Build method) If there is any other code that could help with narrowing down a solution here, please let me know:
return Consumer<DashboardModel>(
builder: (context,model,child) => GestureDetector(
onTap: ()=>handleTap(),
child: CustomPaint(
size: Size(widget.paneWidth, widget.paneHeight),
painter: WindowPainter(context, widget.posLeft, widget.posTop, widget.paneWidth, widget.paneHeight,customPaint),
child: Container(
decoration: BoxDecoration(
color: Colors.amber,
border: Border.all(
color: Colors.red,
width: 8,
),
),
height: widget.paneHeight,
width: widget.paneWidth,
)
)
),
);
Some questions I've looked at to see if they fit the description or could solve the issue include:
- Flutter GestureDetector with CustomPaint not working (Hyper generic, and doesn't seem to be the issue I'm having looking at his code. I can click perfectly fine within the bounds of the GestureDetector, it's just not adjusting for the positional offset)
- flutter CustomPaint and GestureDetector resize both to Image Size (ClipRect won't work here since it's not clipping I'm having an issue with, the GestureDetector is sizing right, just not positioning right)
- child customPaint can't click (This doesn't even have any real substance to it, so it was pretty much useless in this case. I can click perfectly fine, just not where I need to towards the right side of the render sets due to the positional offsetting)