Как создать контейнер с односторонним наклоном во флаттере - PullRequest
0 голосов
/ 08 мая 2020

Я новичок во Flutter. Как мне создать отмеченную здесь форму? Я попытался. Ниже приведен код. enter image description here

Positioned(
                      top: 30.0,
                      left: 15.0,
                      width: 50.0,
                      height: 20.0,
                      child: Container(
                    decoration: BoxDecoration(
                      color: Colors.pink,
                      shape: BoxShape.rectangle
                    ),
                        child: Padding(
                          padding: const EdgeInsets.symmetric(vertical: 4.0,horizontal: 8.0),
                          child: Text('අලුත්ම පුවත',style: TextStyle(color: Colors.white, fontSize: 10.0,fontWeight: FontWeight.bold)),
                        ),
                  ),

полный код

1 Ответ

1 голос
/ 08 мая 2020

Вы можете использовать clipPath для достижения желаемого результата.

Следующий код поможет вам понять больше.

class DeleteWidget extends StatefulWidget {
  @override
  _DeleteWidgetState createState() => _DeleteWidgetState();
}

class _DeleteWidgetState extends State<DeleteWidget> {
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ClipPath(
          clipper: SkewCut(),
          child: Container(
            color: Colors.red,
            width: 200,
            height: 50,
            child: Center(child: Text("Hello World")),
          ),
        ),
      ),
    );
  }
}

class SkewCut extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    final path = Path();
    path.lineTo(size.width, 0);

    path.lineTo(size.width - 20, size.height);
    path.lineTo(0, size.height);
    path.close();

    return path;
  }

  @override
  bool shouldReclip(SkewCut oldClipper) => false;
}
...