搜尋套件、儲存庫與 APP 分類

polygon 封面
套件詳情v0.1.0

polygon

一種繪製多邊形形狀並裁剪它們的簡單方法。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2190
喜歡數
49
Pub 分數
160

安裝套件

flutter pub add polygon

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

polygon 套件為 Flutter 應用程式提供了一種簡單的方式來建立和裁剪多邊形形狀。它讓開發者能夠使用點列表定義自訂多邊形路徑,輕鬆渲染複雜的幾何形狀。該套件支援裁剪作業,可將內容限制在多邊形邊界內,以實現創意視覺效果。非常適合需要非矩形版面或互動式形狀介面的 UI 設計,可在所有主要平台(包括 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 項

原始碼儲存庫

使用此套件的專案