搜索插件、代码仓与 APP 分类

polygon 封面
插件详情v0.1.0

polygon

一种绘制多边形形状并裁剪它们的简单方法。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2190
喜欢数
49
Pub 分数
160

安装插件

flutter pub add polygon

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

polygon 包为 Flutter 应用程序提供了一种简单的方法来创建和裁剪多边形形状。它使开发者能够使用点列表定义自定义多边形路径,从而轻松渲染复杂的几何形状。该包支持裁剪操作,允许内容被限制在多边形边界内,以实现创意视觉效果。非常适合涉及非矩形布局或基于交互式形状的界面设计,可在所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上无缝运行。

适合场景

  • 创建自定义形状的容器
  • 将剪切小部件限制在多边形边界内
  • 设计交互式几何用户界面
  • 使用不规则形状构建游戏或地图界面
  • 动画多边形过渡

主要特点

  • 简单多边形路径创建
  • 内置裁剪支持
  • 跨平台兼容性
  • 与现有 Flutter 小部件的轻松集成
  • 对动态点更新的支持

适合对象

  • 寻求独特形状布局的UI设计师
  • 开发游戏或地图的开发者
  • 需要非矩形裁剪的应用
  • 原型设计几何界面
  • 面向多个平台的项目

使用建议

  • 性能可能因复杂多边形而异
  • 需要谨慎处理点的顺序以确保正确渲染
  • 未针对高频更新进行优化
  • 限于二维形状操作
  • 可能需要额外的逻辑来检测碰撞

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

polygon

Create any polygon easily in Flutter with this package!

Pub Donate

https://user-images.githubusercontent.com/9378033/181354646-63d1d8aa-315e-4ef4-8ff3-e5c3a15341bb.mov

Features

  • Create regular convex polygons.
  • Create regular star polygons.
  • Create a polygon border.
  • Clip any widget with a polygon shape.

Usage

Create a Polygon

With this package you can easily create any kind of polygons by just setting its vertices (in a [(-1,-1);(1,1)] rect).

const polygon = Polygon([
  Offset(0.25, -1),
  Offset(0, -0.25),
  Offset(0.5, 0),
  Offset(-0.25, 1),
  Offset(0, 0.25),
  Offset(-0.5, 0),
]);

You can then create a path from this polygon by using its computePath method. For example you can use it in a CustomPainter:

class PolygonPainter extends CustomPainter {
  PolygonPainter(this.polygon);

  final Polygon polygon;

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawPath(
      polygon.computePath(rect: Offset.zero & size),
      Paint()..color = Colors.yellow.shade800,
    );
  }

  @override
  bool shouldRepaint(PolygonPainter oldDelegate) {
    return oldDelegate.polygon != polygon;
  }
}

sharp

The computePath methods accepts various parameters and you can, for example apply a corner radius to all of the polygon's corners:

rounded

PolygonBorder

This package has also a dedicated ShapeBorder called PolygonBorder, so that you can easily apply a color, a border, an image to the polygon or clip anything through Clip.shape.

DecoratedBox(
  decoration: ShapeDecoration(
    shape: PolygonBorder(
      polygon: polygon,
      turn: 0.125,
      radius: 20.0,
      borderAlign: BorderAlign.outside,
      side:  BorderSide(
        width: 4,
        color: Colors.red,
      ),
    ),
    color: Colors.pink,
  ),
  child: const SizedBox(
    height: 400,
    width: 400,
  ),
),
Specialized polygons.

This package comes with two specialized polygons: A RegularConvexPolygon which can create triangles, tetragons, pentagons, etc. A RegularStarPolygon which can create various star shapes.

https://user-images.githubusercontent.com/9378033/181354589-1c12b68b-2ecc-4ded-a46b-16fe03d6cd57.mov

Sponsoring

I'm working on my packages on my free-time, but I don't have as much time as I would. If this package or any other package I created is helping you, please consider to sponsor me. By doing so, I will prioritize your issues or your pull-requests before the others.

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目