Skip to content

Commit

Permalink
fix: It should be possible to re-add ColorEffect (#2469)
Browse files Browse the repository at this point in the history
Currently you'll get an error that the late final _original field is already initialized if you re-add effect to a component, since that field is set in onMount. This PR simply removes final from that field so that it can be updated in onMount.
  • Loading branch information
spydon authored Apr 6, 2023
1 parent c6f467b commit 6fa9e9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flame/lib/src/effects/color_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:flutter/material.dart';
class ColorEffect extends ComponentEffect<HasPaint> {
final String? paintId;
final Color color;
late final ColorFilter? _original;
ColorFilter? _original;
late final Tween<double> _tween;

ColorEffect(
Expand Down
23 changes: 23 additions & 0 deletions packages/flame/test/effects/color_effect_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,28 @@ void main() {
);
},
);

testWithFlameGame(
'can be re-added in the component tree',
(game) async {
final component = _PaintComponent();
await game.ensureAdd(component);

final effect = ColorEffect(
Colors.red,
const Offset(0, 1),
EffectController(duration: 1),
);
await component.ensureAdd(effect);
game.update(0.5);
effect.removeFromParent();
game.update(0.0);
component.add(effect);
expect(
() => game.update(0),
returnsNormally,
);
},
);
});
}

0 comments on commit 6fa9e9d

Please sign in to comment.