1

I have problems creating a triangle at the edge of a rectangle, and be able to write inside using Flutter platform, you can see this example: enter image description here

1
  • Yara Hassan if this answer was useful please checked like accepted. Commented Jan 13, 2022 at 16:28

1 Answer 1

3

You can use customPainter to do that this is the way:

import 'package:flutter/material.dart';

class CustomFigure extends StatelessWidget {
  const CustomFigure({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: double.infinity,
        width: double.infinity,
        child: CustomPaint(
          painter: _Figure(),
        ),
      ),
    );
  }
}

class _Figure extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final paint = new Paint();
    paint.color = Colors.blue;
    paint.style = PaintingStyle.stroke;
    paint.strokeWidth = 5;

    final path = new Path();

    // Drawing triangle
    path.moveTo(10, size.height * 0.3);
    path.lineTo(size.width * 0.5, 50);
    path.lineTo(10, 50);
    path.lineTo(10, size.height * 0.3);

    // Drawing figure
    path.moveTo(10, size.width * 0.70);
    path.lineTo(size.width * 0.55, 50);
    path.lineTo(size.width - 10, 50);
    path.lineTo(size.width - 10, size.height * 0.5);
    path.lineTo(10, size.height * 0.5);
    path.lineTo(10, size.width * 0.70);

    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}


enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.