搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。