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

infinite_canvas 封面
套件詳情v0.0.10

infinite_canvas

一個基於 InteractiveViewer 和 CustomMultiChildLayout 的可擴展無限畫布,適用於 Flutter,允許使用組件作為子組件並可移動或選擇。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
395
喜歡數
82
Pub 分數
140

安裝套件

flutter pub add infinite_canvas

套件介紹

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

Infinite Canvas 是一個 Flutter 套件,提供了一個基於 InteractiveViewer 和 CustomMultiChildLayout 的可擴展、互動式無限畫布。它允許開發者將任何小部件作為子項放置,並透過平移、縮放和選擇來操作它們。非常適合用於繪圖、繪畫和簽名應用,支援在無限工作區中動態放置內容。該畫布能跨平台無縫適應,為 Android、iOS、Web、macOS、Windows 和 Linux 提供一致的行為。

適用情境

  • 數位白板
  • 互動藝術創作
  • 簽名捕獲
  • 協作設計工具
  • 教育繪圖
  • 文件註釋

主要特色

  • 支援任意元件作為子元件
  • 透過 InteractiveViewer 實現平移與縮放
  • 可自訂配置的 CustomMultiChildLayout
  • 可選擇且可移動的子元素
  • 跨平台相容性
  • 可擴展的架構,用於自訂互動

適合對象

  • 繪圖與草圖應用
  • 互動式教育軟體
  • 設計協作工具
  • 文件註釋系統
  • 創意編程專案

使用建議

  • 當子組件過多時,效能可能會下降
  • 需要仔細管理組件狀態
  • 未針對高頻率即時更新進行優化
  • 內建的手勢支援有限,僅限於平移/縮放
  • 可能需要額外的邏輯來處理複雜的選取行為

原始 README

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

Infinite Canvas

infinite_canvas

Flutter infinite canvas that can be zoomed and panned.

There is also a menu for common actions and marquee for multiple selection.

Example

import 'package:flutter/material.dart';
import 'package:infinite_canvas/infinite_canvas.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: const Example(),
      theme: ThemeData.light(useMaterial3: true),
      darkTheme: ThemeData.dark(useMaterial3: true),
      themeMode: ThemeMode.system,
    );
  }
}

class Example extends StatefulWidget {
  const Example({super.key});

  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
  late InfiniteCanvasController controller;

  @override
  void initState() {
    super.initState();
    final rectangleNode = InfiniteCanvasNode(
      key: UniqueKey(),
      label: 'Rectangle',
      offset: const Offset(400, 300),
      size: const Size(200, 200),
      child: Builder(
        builder: (context) {
          return CustomPaint(
            isComplex: true,
            willChange: true,
            painter: InlineCustomPainter(
              brush: Paint(),
              builder: (brush, canvas, rect) {
                // Draw rect
                brush.color = Theme.of(context).colorScheme.secondary;
                canvas.drawRect(rect, brush);
              },
            ),
          );
        },
      ),
    );
    final triangleNode = InfiniteCanvasNode(
      key: UniqueKey(),
      label: 'Triangle',
      offset: const Offset(550, 300),
      size: const Size(200, 200),
      child: Builder(
        builder: (context) {
          return CustomPaint(
            painter: InlineCustomPainter(
              brush: Paint(),
              builder: (brush, canvas, rect) {
                // Draw triangle
                brush.color = Theme.of(context).colorScheme.secondaryContainer;
                final path = Path();
                path.addPolygon([
                  rect.topCenter,
                  rect.bottomLeft,
                  rect.bottomRight,
                ], true);
                canvas.drawPath(path, brush);
              },
            ),
          );
        },
      ),
    );
    final circleNode = InfiniteCanvasNode(
      key: UniqueKey(),
      label: 'Circle',
      offset: const Offset(500, 450),
      size: const Size(200, 200),
      child: Builder(
        builder: (context) {
          return CustomPaint(
            painter: InlineCustomPainter(
              brush: Paint(),
              builder: (brush, canvas, rect) {
                // Draw circle
                brush.color = Theme.of(context).colorScheme.tertiary;
                canvas.drawCircle(rect.center, rect.width / 2, brush);
              },
            ),
          );
        },
      ),
    );
    final nodes = [
      rectangleNode,
      triangleNode,
      circleNode,
    ];
    controller = InfiniteCanvasController(nodes: nodes, edges: [
      InfiniteCanvasEdge(
        from: rectangleNode.key,
        to: triangleNode.key,
        label: '4 -> 3',
      ),
      InfiniteCanvasEdge(
        from: rectangleNode.key,
        to: circleNode.key,
        label: '[] -> ()',
      ),
      InfiniteCanvasEdge(
        from: triangleNode.key,
        to: circleNode.key,
      ),
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Infinite Canvas Example'),
        centerTitle: false,
      ),
      body: InfiniteCanvas(
        controller: controller,
      ),
    );
  }
}

class InlineCustomPainter extends CustomPainter {
  const InlineCustomPainter({
    required this.brush,
    required this.builder,
    this.isAntiAlias = true,
  });
  final Paint brush;
  final bool isAntiAlias;
  final void Function(Paint paint, Canvas canvas, Rect rect) builder;

  @override
  void paint(Canvas canvas, Size size) {
    final rect = Offset.zero & size;
    brush.isAntiAlias = isAntiAlias;
    canvas.save();
    builder(brush, canvas, rect);
    canvas.restore();
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}

Links

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。