Skip to content

Commit 0872555

Browse files
committed
StrokePath fillColor: fill the shape the points enclose, behind the line
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015oUVfwrhf6R1MWmqpTVtPG
1 parent b70f6b0 commit 0872555

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎lib/src/behavior_fields.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,11 @@ abstract final class StrokePathFields {
861861
doc: 'How the drawing eases.',
862862
);
863863
static const drawKey = PropDef<String>('drawKey', Codecs.string, '', doc: 'Draws again from nothing when it changes.');
864+
static const fillColor = PropDef<Color?>('fillColor', Codecs.color, null,
865+
doc: 'Fills the shape the points enclose, behind the line (fading in as it draws).');
864866
static const List<PropDef<Object?>> all = [
865867
points, xUnit, yUnit, curve, color, width, progress, dashPattern, cap, inFront, //
866-
drawMs, drawDelayMs, drawCurve, drawKey,
868+
drawMs, drawDelayMs, drawCurve, drawKey, fillColor,
867869
];
868870
}
869871

‎lib/src/behaviors.dart‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,10 +2482,15 @@ final class StrokePath extends _Value {
24822482
this.drawDelayMs = 0,
24832483
this.drawCurve = AnimationCurve.easeInOut,
24842484
this.drawKey = '',
2485+
this.fillColor,
24852486
});
24862487

24872488
final List<Offset> points;
24882489
final PathUnit xUnit, yUnit;
2490+
2491+
/// The shape the points enclose (the path closed), filled behind the
2492+
/// line: a hand-drawn box with its own wobble. It fades in as the line
2493+
/// draws (its alpha times [progress]). Null: no fill.
24892494
final PathCurve curve;
24902495
final Color color;
24912496
final double width;
@@ -2511,6 +2516,8 @@ final class StrokePath extends _Value {
25112516
/// as `strokePath.drawKey`, e.g. `${route.id}`).
25122517
final String drawKey;
25132518

2519+
final Color? fillColor;
2520+
25142521
/// Whether a running app animates it.
25152522
bool get draws => drawMs > 0;
25162523

@@ -2529,6 +2536,7 @@ final class StrokePath extends _Value {
25292536
drawDelayMs: drawDelayMs,
25302537
drawCurve: drawCurve,
25312538
drawKey: drawKey,
2539+
fillColor: fillColor,
25322540
);
25332541

25342542
static StrokePath? fromJson(Object? json) {
@@ -2550,6 +2558,7 @@ final class StrokePath extends _Value {
25502558
drawDelayMs: r.ms('drawDelayMs', 0),
25512559
drawCurve: r.curve('drawCurve', AnimationCurve.easeInOut),
25522560
drawKey: readString(m['drawKey']) ?? (m['drawKey'] == null ? '' : '${m['drawKey']}'),
2561+
fillColor: r.color('fillColor'),
25532562
);
25542563
}
25552564

@@ -2582,11 +2591,12 @@ final class StrokePath extends _Value {
25822591
..i('drawDelayMs', drawDelayMs, 0)
25832592
..e('drawCurve', drawCurve, AnimationCurve.easeInOut);
25842593
if (drawKey.isNotEmpty) j['drawKey'] = drawKey;
2594+
if (fillColor != null) j['fillColor'] = fillColor!.toJson();
25852595
return j;
25862596
}
25872597

25882598
@override
2589-
List<Object?> get props => [points, xUnit, yUnit, curve, color, width, progress, dashPattern, cap, inFront, drawMs, drawDelayMs, drawCurve, drawKey];
2599+
List<Object?> get props => [points, xUnit, yUnit, curve, color, width, progress, dashPattern, cap, inFront, drawMs, drawDelayMs, drawCurve, drawKey, fillColor];
25902600
}
25912601

25922602
/// Text that types itself out in a running app, like a typewriter or a

‎test/behaviors_test.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,12 @@ void main() {
267267
expect(Typewriter.fromJson({'grow': true})!.toJson(), {'grow': true});
268268
expect(Typewriter.fromJson({})!.grow, isFalse);
269269
});
270+
271+
test('strokePath.fillColor round-trips; absent is no fill', () {
272+
expect(StrokePath.fromJson({'points': []})!.fillColor, isNull);
273+
final p = StrokePath.fromJson({'points': [[0, 0], [10, 0], [10, 10]], 'fillColor': '#59FFF6DE'})!;
274+
expect(p.fillColor, const Color(0x59FFF6DE));
275+
expect(StrokePath.fromJson(p.toJson()), p);
276+
expect(p.copyWith(progress: 0.5).fillColor, p.fillColor);
277+
});
270278
}

0 commit comments

Comments
 (0)