@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
3
3
import '../utils/datetime.dart' ;
4
4
5
5
/// An action that can be performed on a Gantt activity.
6
- class GantActivityAction {
6
+ class GanttActivityAction {
7
7
/// The icon representing the action.
8
8
final IconData icon;
9
9
@@ -14,7 +14,7 @@ class GantActivityAction {
14
14
final String ? tooltip;
15
15
16
16
/// Creates an activity action with an icon, tap handler, and optional tooltip.
17
- const GantActivityAction ({
17
+ const GanttActivityAction ({
18
18
required this .icon,
19
19
required this .onTap,
20
20
this .tooltip,
@@ -25,7 +25,7 @@ class GantActivityAction {
25
25
///
26
26
/// Each activity has a start/end date, title, and optional styling properties.
27
27
/// Activities can be hierarchical with parent-child relationships.
28
- class GantActivity <T > {
28
+ class GanttActivity <T > {
29
29
/// Unique identifier for the activity.
30
30
late String key;
31
31
@@ -54,16 +54,16 @@ class GantActivity<T> {
54
54
final Widget ? iconTitle;
55
55
56
56
/// The segments that make up this activity.
57
- final List <GantActivitySegment >? segments;
57
+ final List <GanttActivitySegment >? segments;
58
58
59
59
/// Child activities that are hierarchically under this one.
60
- final List <GantActivity >? children;
60
+ final List <GanttActivity >? children;
61
61
62
62
/// Actions that can be performed on this activity.
63
- final List <GantActivityAction >? actions;
63
+ final List <GanttActivityAction >? actions;
64
64
65
65
/// Callback when the activity cell is tapped.
66
- final Function (GantActivity activity)? onCellTap;
66
+ final Function (GanttActivity activity)? onCellTap;
67
67
68
68
/// Builder function for custom single cell rendering.
69
69
final Widget Function (DateTime cellDate)? cellBuilder;
@@ -75,24 +75,30 @@ class GantActivity<T> {
75
75
final bool showCell;
76
76
77
77
/// Builder function for custom cell rendering.
78
- final Widget Function (GantActivity activity)? builder;
78
+ final Widget Function (GanttActivity activity)? builder;
79
79
80
80
/// Optional custom data associated with the activity.
81
81
final T ? data;
82
82
83
- GantActivity ? _parent;
83
+ GanttActivity ? _parent;
84
84
85
85
/// The parent activity, if this is a child activity.
86
- GantActivity ? get parent => _parent;
86
+ GanttActivity ? get parent => _parent;
87
87
88
- /// Creates a [GantActivity] with the specified properties.
88
+ /// The limit of the start date of the activity.
89
+ late DateTime ? limitStart;
90
+
91
+ /// The limit of the end date of the activity.
92
+ late DateTime ? limitEnd;
93
+
94
+ /// Creates a [GanttActivity] with the specified properties.
89
95
///
90
96
/// Throws an [AssertionError] if:
91
97
/// - Start date is after end date
92
98
/// - Only one between [title] and [titleWidget] must be provided
93
99
/// - Any segment dates fall outside the activity dates
94
100
/// - Any child activity dates fall outside this activity's dates
95
- GantActivity ({
101
+ GanttActivity ({
96
102
required this .key,
97
103
required DateTime start,
98
104
required DateTime end,
@@ -111,6 +117,8 @@ class GantActivity<T> {
111
117
this .showCell = true ,
112
118
this .builder,
113
119
this .data,
120
+ this .limitStart,
121
+ this .limitEnd,
114
122
}) : assert (
115
123
start.toDate.isBeforeOrSame (end.toDate) &&
116
124
((title == null ) != (titleWidget == null )) &&
@@ -145,22 +153,65 @@ class GantActivity<T> {
145
153
String toString () => title ?? super .toString ();
146
154
147
155
/// Gets a flat list of this activity and all its descendants.
148
- List <GantActivity > get plainList => [this , ...children? .plainList ?? []];
156
+ List <GanttActivity > get plainList => [this , ...children? .plainList ?? []];
157
+
158
+ bool validStartMoveToParent (int days) =>
159
+ parent == null ||
160
+ ! parent! .showCell ||
161
+ start.addDays (days).isAfterOrSame (parent! .start);
162
+
163
+ bool validStartMoveToChildren (int days) =>
164
+ (children? .isEmpty ?? true ) == true ||
165
+ start
166
+ .addDays (days)
167
+ .isBeforeOrSame (
168
+ DateTimeEx .firstDateFromList (
169
+ children! .map ((e) => e.start).toList (),
170
+ ),
171
+ );
172
+
173
+ bool validEndMoveToParent (int days) =>
174
+ parent == null ||
175
+ ! parent! .showCell ||
176
+ end.addDays (days).isBeforeOrSame (parent! .end);
177
+
178
+ bool validEndMoveToChildren (int days) =>
179
+ (children? .isEmpty ?? true ) == true ||
180
+ end
181
+ .addDays (days)
182
+ .isAfterOrSame (
183
+ DateTimeEx .lastDateFromList (children! .map ((e) => e.end).toList ()),
184
+ );
185
+
186
+ bool validMoveToParent (int days) =>
187
+ validStartMoveToParent (days) && validEndMoveToParent (days);
188
+
189
+ bool validStartMove (int days) =>
190
+ validStartMoveToParent (days) &&
191
+ validStartMoveToChildren (days) &&
192
+ (limitStart == null || start.addDays (days).isAfterOrSame (limitStart! ));
193
+
194
+ bool validEndMove (int days) =>
195
+ validEndMoveToParent (days) &&
196
+ validEndMoveToChildren (days) &&
197
+ (limitEnd == null || end.addDays (days).isBeforeOrSame (limitEnd! ));
198
+
199
+ bool validMove (int days) => validStartMove (days) && validEndMove (days);
149
200
}
150
201
151
- /// Extension methods for working with lists of [GantActivity ] .
152
- extension GantActivityListExtension on List <GantActivity > {
202
+ /// Extension methods for working with lists of [GanttActivity ] .
203
+ extension GanttActivityListExtension on List <GanttActivity > {
153
204
/// Gets a flat list of all activities and their descendants.
154
- List <GantActivity > get plainList {
155
- final as = < GantActivity > [];
205
+ List <GanttActivity > get plainList {
206
+ final as = < GanttActivity > [];
156
207
for (var a in this ) {
157
208
as .addAll (a.plainList);
158
209
}
159
210
return as ;
160
211
}
161
212
162
213
/// Finds an activity by its key in the flattened list.
163
- GantActivity ? getFromKey (String key) {
214
+ GanttActivity ? getFromKey (String key) {
164
215
final i = plainList.indexWhere ((e) => e.key == key);
165
216
return i < 0 ? null : plainList[i];
166
217
}
@@ -169,7 +220,7 @@ extension GantActivityListExtension on List<GantActivity> {
169
220
/// A segment of a Gantt activity.
170
221
///
171
222
/// Activities can be divided into segments to show progress or phases.
172
- class GantActivitySegment {
223
+ class GanttActivitySegment {
173
224
/// The start date of the segment.
174
225
late DateTime start;
175
226
@@ -183,15 +234,15 @@ class GantActivitySegment {
183
234
final String description;
184
235
185
236
/// Callback when the segment is tapped.
186
- final Function (GantActivity activity)? onTap;
237
+ final Function (GanttActivity activity)? onTap;
187
238
188
239
/// The color of the segment.
189
240
final Color ? color;
190
241
191
- /// Creates a [GantActivitySegment ] .
242
+ /// Creates a [GanttActivitySegment ] .
192
243
///
193
244
/// Throws an [AssertionError] if start date is after end date.
194
- GantActivitySegment ({
245
+ GanttActivitySegment ({
195
246
required DateTime start,
196
247
required DateTime end,
197
248
required this .title,
0 commit comments