Flutter API
yotsuba_gantt 是原生 Flutter Widget,不使用 WebView。
YotsubaGantt 参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
tasks | List<YgTask> | 必填 | 有序、不可变任务行 |
controller | YgGanttController? | - | 命令式控制 |
rangeStart / rangeEnd | DateTime? | 数据前后 7 天 | 任意时间范围 |
viewMode | YgViewMode | week | 年、季、月、周、日、时 |
onViewModeChanged | ValueChanged<YgViewMode>? | - | 维度变化 |
theme | YgGanttThemeData? | light() | 视觉令牌 |
height | double | 520 | 固定高度,最小 240 |
sidebarWidth | double | 280 | 初始任务表宽度 |
minSidebarWidth / maxSidebarWidth | double | 180 / 480 | 分栏限制 |
sidebarResizeStep | double | 8 | 分栏吸附步长 |
resizableSidebar | bool | true | 允许拖动分栏 |
autoFocus | YgAutoFocus | dense | none、dense、earliest、today |
denseWindow | Duration | 14 天 | 密度桶窗口 |
showDependencies / showProgress | bool | true | 依赖线和进度 |
showOffscreenIndicators | bool | true | 逐行视口外入口 |
linkGroup | YgGanttLinkGroup? | - | 多图联动组 |
syncMode | YgSyncMode | none | none、scroll、view、all |
interactive | bool | true | 允许拖动和缩放 |
selectedTaskId | String? | - | 宿主选中任务 |
entryTransition | YgEntryTransition | fadeSlide | 虚拟行入场 |
entryDuration | Duration | 180 ms | 入场时长 |
Builders
| 参数 | 类型 | 说明 |
|---|---|---|
taskBarBuilder | YgTaskBarBuilder | 任务条内部;获得任务、行号、选中态和几何 |
rowHeaderBuilder | YgRowHeaderBuilder | 左侧任务行 |
entryTransitionBuilder | YgEntryTransitionBuilder | 使用提供的 Animation<double> 包装新行 |
edgeIndicatorBuilder | YgEdgeIndicatorBuilder | 左右边缘入口;调用 details.jump() 定位 |
回调
| 参数 | 载荷 | 说明 |
|---|---|---|
onTaskTap | YgTask | 单击任务 |
onTaskDoubleTap | YgTask | 双击任务 |
onTaskChanged | YgTaskChange | 移动或缩放后的不可变替换值 |
onVisibleRangeChanged | YgVisibleRange | 当前日期与行窗口;每帧最多一次 |
YgTaskChange.previous 是交互前对象,task 是建议替换值,kind 为 move、resizeStart 或 resizeEnd。
YgTask
| 字段 | 类型 | 说明 |
|---|---|---|
id / title | String | 稳定 ID 与标题 |
start / end | DateTime | 起止时间 |
progress | double | 0...1 |
kind | YgTaskKind | task、project、milestone |
barStyle | YgBarStyle | solid、outline、soft、progress |
color | Color? | 任务颜色 |
parentId / owner | String? | 层级与负责人 |
dependencies | List<String> | 前置任务 ID |
metadata | Map<String, Object?> | 宿主业务字段 |
任务不可变;使用 copyWith() 创建替换对象。
YgGanttController
dart
controller.isAttached
await controller.scrollToDate(date, duration: duration)
await controller.scrollTaskIntoView(taskId, duration: duration)
await controller.scrollToRow(rowIndex, duration: duration)
controller.setView(YgViewMode.month)
await controller.fitToTasks()YgGanttThemeData
主题开放背景、任务表、表头、网格、主色、今天线、主/次文字、依赖线颜色,任务与表头文字样式,以及 rowHeight、taskHeight、taskRadius。可从 YgGanttThemeData.light(seed:) 开始并用 copyWith() 修改。
