1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] How to centre child on custom paint in flutter like this image?

Discussão em 'Mobile' iniciado por Stack, Outubro 15, 2024 às 22:12.

  1. Stack

    Stack Membro Participativo

    i was trying to make something looks like this [​IMG] here is my code CustomPaint( painter: HexagonPainter(center: Offset(100, 100), radius: 65), child: Icon(Icons.speed), ); but I'm getting result like this [​IMG] they are not together ..how can I archive this custom painter code `

    class HexagonPainter extends CustomPainter {
    static const int SIDES_OF_HEXAGON = 6;
    final double? radius;
    final Offset? center;

    HexagonPainter({this.center, this.radius});

    @override
    void paint(Canvas canvas, Size size) {
    Paint paint = Paint()..color = Color(0xff05c2c9);
    Path path = createHexagonPath();

    canvas.drawPath(path, paint);
    }

    Path createHexagonPath() {
    final path = Path();
    var angle = (math.pi * 2) / SIDES_OF_HEXAGON;
    Offset firstPoint =
    Offset(radius! * math.cos(0.0), radius! * math.sin(0.0));
    path.moveTo(firstPoint.dx + center!.dx, firstPoint.dy + center!.dy);
    for (int i = 1; i <= SIDES_OF_HEXAGON; i++) {
    double x = radius! * math.cos(angle * i) + center!.dx;
    double y = radius! * math.sin(angle * i) + center!.dy;
    path.lineTo(x, y);
    }

    path.close();

    return path;
    }

    @override
    bool shouldRepaint(CustomPainter oldDelegate) => false;


    } `

    Continue reading...

Compartilhe esta Página