CustomPainter works differently when object with it is rotated

  android-studio, flutter, flutter-layout, paint, rotation

There is an SVG map and a CustomPainter that allows to draw a route from one point to another. The problem is that when quarterTurns: 1 in RotatedBox Widget, the route is built correctly, but when quarterTurns: 0 in the same RotatedBox, the route is built in absolutely different incorrect way.

The route is built with help of data on the outer server, and the data for the route is absolutely the same both for the vertically and horizontally rotated map. However, the routes are drawn differently.

Can you please help if you have any ideas how to fix this bug and make route the same on vertically and horizontally rotated map?

Part of the code is below, links for the screenshots with routes differences: horizontal and vertical.

I tried to remove InteractiveViewer, but it didn’t help. Repeating, the server gives the same route for both vertical and horizontal map, so the problem must be in the drawing in the app.

var mapRoutePainter = InrouteMapPainter(); // CustomPainter responsible for route building
var mapAssetPaint = CustomPaint();

var mapAsset = SvgPicture.asset(
'assets/svg/test.svg',
 allowDrawingOutsideViewBox: false,
);

Column(
          children: <Widget>[
            RotatedBox(
              quarterTurns: 0, // the line responsible for rotation
              child: Padding(
                padding: const EdgeInsets.only(
                  top: 50.0,
                  bottom: 50.0,
                ),
                child: InteractiveViewer(
                  boundaryMargin: EdgeInsets.all(100.0),
                  maxScale: 10.0,
                  child: LayoutBuilder(
                    builder:
                        (BuildContext context, BoxConstraints constraints) {
                      mapAssetPaint = CustomPaint(
                        size: Size(constraints.maxHeight, 300),
                        foregroundPainter: mapRoutePainter,
                        child: Transform.scale(
                          alignment: Alignment.center,
                          origin: global["mapScaleOrigin"],
                          scale: global["mapScaler"],
                          child: Transform.translate(
                            offset: Offset(-global["mapOffset"].dx,
                                -global["mapOffset"].dy),
                            child: mapAsset,
                          ),
                        ),
                      );
                      return mapAssetPaint;
                    },
                  ),
                ),
              ),
            ),
          ],
        ),

Source: Android Studio Questions

LEAVE A COMMENT