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

套件詳情v1.0.1

path_drawing

一個用於協助建立和操作(Canvas)路徑的 Flutter 庫

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
93.1萬
喜歡數
223
Pub 分數
140

安裝套件

flutter pub add path_drawing

套件介紹

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

一個 Flutter 庫,旨在簡化 Canvas 路徑的建立與操作。它提供產生常見形狀、變換路徑以及執行幾何運算(如偏移、縮放和合併路徑)的實用函數。非常適合在任何 Flutter 平台上進行自訂繪圖、動畫或複雜向量圖形開發的開發者使用。該套件可提升精確度並減少處理複雜路徑邏輯時的重複程式碼。

適用情境

  • 在畫布中建立自訂形狀
  • 動畫路徑變換
  • 產生幾何圖案
  • 構建基於向量的 UI 組件
  • 透過程式設計方式操作路徑幾何

主要特色

  • 輕鬆的路徑建構工具
  • 路徑變換方法
  • 支援路徑交集與聯集
  • 跨平台相容性
  • 最小依賴開銷

適合對象

  • Flutter 開發人員建構自定義圖形
  • UI設計師實現向量藝術
  • 需要路徑控制的動畫創作者
  • 需要精確形狀渲染的應用程式

使用建議

  • 需要理解 Canvas 和 Path 概念
  • 僅限路徑特定作業
  • 不適用於完整SVG渲染
  • 最佳搭配自定繪畫小部件使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

path_drawing

pub package

A Flutter library to assist with creating and manipulating paths.

Currently supports parsing a Path from an SVG path data string (including normalizing the path commands to be amenable to Flutter's exposed Path methods).

Dash paths has an initial implementation that relies on flutter 0.3.6 at a minimum.

Planned for future release(s):

  • Trim paths

Example

Parse some path from svg string:

import 'package:path_drawing/path_drawing.dart';

final trianglePath = parseSvgPathData('M150 0 L75 200 L225 200 Z');

Create CustomPainter:

class FilledPathPainter extends CustomPainter {
  const FilledPathPainter({
    @required this.path,
    @required this.color,
  });

  final Path path;
  final Color color;

  @override
  bool shouldRepaint(FilledPathPainter oldDelegate) =>
      oldDelegate.path != path || oldDelegate.color != color;

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawPath(
      path,
      Paint()
        ..color = color
        ..style = PaintingStyle.fill,
    );
  }

  @override
  bool hitTest(Offset position) => path.contains(position);
}

Use it inside CustomPaint:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => print('tap'),
      child: CustomPaint(
        painter: FilledPathPainter(
          path: trianglePath,
          color: Colors.blue,
        ),
      ),
    );
  }
}

More examples can be found in example folder

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案