flutter - 如何在 flutter 中获取剪辑的 Container() 的边框

标签 flutter flutter-web

我正在使用“polygon_clipper 1.0.2”来剪辑我的容器。

Container(
    height: 100,
    width: 100,
    child: ClipPolygon(
          child: Container(
               color: Theme.of(context).primaryColor,
              ),
          sides: 6,
          borderRadius: 10,
         ),
   ),

这里我得到一个填充六边形,其顶点是弯曲的。

我想要一个只有边框的六边形。

以下代码给出了一个具有圆形边框的容器。 我想要类似的结果,但边数应该是 6。

Container(
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12),
          border: Border.all(
                            width: 2, color: Theme.of(context).primaryColor
                            ),
           ),
     height: 100,
     width: 100,
)

有解决办法吗?

最佳答案

您可以使用PolygonBorder:

import 'package:polygon_clipper/polygon_border.dart';
Container(
  height: 100,
  width: 100,
  decoration: ShapeDecoration(
    shape: PolygonBorder(
      sides: 6,
      borderRadius: 10,
      border: BorderSide(
        color: Theme.of(context).primaryColor,
      )
    ),
  )
),

关于flutter - 如何在 flutter 中获取剪辑的 Container() 的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63209936/

相关文章:

flutter - 停止监听并重新开始监听RxDart中的流

flutter - “该表达式的类型为 'void',因此无法使用其值。” Flutter 中的 setState() 错误

flutter - 运行flutter pub升级的错误在5分钟后停止

flutter - 尝试为 flutter_web 项目提供服务时无法创建本地服务器(地址已被使用)

debugging - 如何在Flutter web中调试或打印?

flutter - 在Web的Flutter中实现访客计数器

heroku 上的 Python 应用程序无法打开 Stripe 支付页面

android - 如果 RaisedButton.icon() 上的构造函数中的图标值为空,如何保持图标禁用?

flutter - 将函数作为参数传递给小部件

android - 如何在 Flutter 中报告静默崩溃