Флаттер нестандартной формы - PullRequest
0 голосов
/ 08 апреля 2020

Я пытаюсь сделать контейнер нестандартной формы во флаттере, но я не могу получить симметричную c версию (симметрию c в начало) формы, которую я сделал, I NEED TO GET SYMMETRIC OF BLUE ONEenter image description here

class BackgroundClipper1 extends CustomClipper<Path> {
  @override
  getClip(Size size) {
    var path = Path();
    path.moveTo(0, 0);

    path.lineTo(size.width,0);
    path.lineTo(0,size.height); 
    return path;
  }

  @override
  bool shouldReclip(CustomClipper oldClipper) {
    return true;
  }
}

. , , Как я это называю в моем коде.

child: ClipPath(
                  clipper: BackgroundClipper1(),
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    height: MediaQuery.of(context).size.height * 0.5,
                    decoration: BoxDecoration(
                        gradient: LinearGradient(
                            colors: [Colors.blue, Colors.blueAccent])),
                  )),

1 Ответ

1 голос
/ 08 апреля 2020

Попробуйте это ..

class MyTriangle extends CustomPainter {
  final Color strokeColor;

  MyTriangle({this.strokeColor = Colors.white});

  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = strokeColor
      ..style = PaintingStyle.fill;

    canvas.drawPath(getTrianglePath(size.width, size.height), paint);
  }

  Path getTrianglePath(double x, double y) {
    return Path()
      ..moveTo(y, 0)
      ..lineTo(y, x)
      ..lineTo(0, x)
      ..lineTo(y, 0);
  }

  @override
  bool shouldRepaint(MyTriangle oldDelegate) {
    return oldDelegate.strokeColor != strokeColor;
  }
}

и использование

Container(
        width: 150,
        height: 150,
        child: CustomPaint(painter: MyTriangle(strokeColor: Colors.green)),
      )

ВЫХОД

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...