Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在flatter中将容器边框中的文本作为标题/标题写入_Flutter - Fatal编程技术网

Flutter 如何在flatter中将容器边框中的文本作为标题/标题写入

Flutter 如何在flatter中将容器边框中的文本作为标题/标题写入,flutter,Flutter,我应该如何在容器的边界上书写“合作关系”(如下图所示) 您可以使用CustomPainter或自定义shapeorder进行操作,这是使用shapeorder的一个示例: class CustomBorderWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Material(

我应该如何在容器的边界上书写“合作关系”(如下图所示)


您可以使用
CustomPainter
或自定义
shapeorder
进行操作,这是使用shapeorder的一个示例:

        class CustomBorderWidget extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return Material(
              color: Colors.black,
              shape: _HexagonBorder(),
              child: Padding(
                padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 30.0),
                child: Text(
                  "Partnership",
                  style: TextStyle(color: Colors.white, fontWeight: FontWeight.w600),
                ),
              ),
            );
          }
        }

        class _HexagonBorder extends ShapeBorder {
          const _HexagonBorder();

          @override
          EdgeInsetsGeometry get dimensions {
            return const EdgeInsets.only();
          }

          @override
          Path getInnerPath(Rect rect, {TextDirection textDirection}) {
            return getOuterPath(rect, textDirection: textDirection);
          }

          @override
          Path getOuterPath(Rect rect, {TextDirection textDirection}) {
            return Path()
              ..moveTo(rect.left + rect.width / 6.0, rect.top)
              ..lineTo(rect.right - rect.width / 6.0, rect.top)
              ..lineTo(rect.right, rect.top + rect.height / 2.0)
              ..lineTo(rect.right - rect.width / 6.0, rect.bottom)
              ..lineTo(rect.left + rect.width / 6.0, rect.bottom)
              ..lineTo(rect.left, rect.bottom - rect.height / 2.0)
              ..close();
          }

          @override
          void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {}

          // This border doesn't support scaling.
          @override
          ShapeBorder scale(double t) {
            return null;
          }
        }