flame
flame copied to clipboard
Unable to restart Effect with a DelayedEffectController
Current bug behavior
When resetting an effect with a DelayedEffectController, the component is not being re-animated
Expected behavior
When resetting an effect with a DelayedEffectController, the component should re-animated
Steps to reproduce
- On-load boxes are being animated;
- Click in the bottom right corner to restart the animation;
- And check the behavior of the blue box;
Example: https://zapp.run/edit/zuse06g7usf0?theme=dark&lazy=false
Flutter doctor output
[!] Flutter (Channel stable, 3.13.0, on macOS 14.1.1 23B81 darwin-arm64, locale en-PT)
• Flutter version 3.13.0 on channel stable at ../flutter
! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at ../flutter. Consider adding flutter/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision efbf63d9c6 (3 months ago), 2023-08-15 21:05:06 -0500
• Engine revision 1ac611c64e
• Dart version 3.1.0
• DevTools version 2.25.0
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at ../Android/sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15A507
• CocoaPods version 1.13.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[✓] IntelliJ IDEA Community Edition (version 2023.1.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.84.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.44.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.1.1 23B81 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.159
[✓] Network resources
• All expected network resources are available.
More environment information
- Flame version: 1.10.1
Log information
None
More information
Looking into source code, looks like DelayedEffectController has a DurationController as a property that is not being restarted when DelayedEffectController effect controller is being restarted. I was able to solve it, propagating the call of the setToStart method to DelayedEffectController _child controller.
import 'package:flame/src/effects/controllers/effect_controller.dart';
import 'package:flame/src/effects/effect.dart';
/// An effect controller that waits for [delay] seconds before running the
/// child controller. While waiting, the progress will be reported at 0.
class DelayedEffectController extends EffectController {
DelayedEffectController(EffectController child, {required this.delay})
: assert(delay >= 0, 'Delay must be non-negative: $delay'),
_child = child,
_timer = 0,
super.empty();
final EffectController _child;
final double delay;
double _timer;
// ......
@override
void setToStart() {
_timer = 0;
// ===
// Here should be called => _child.setToStart();
// ===
}
@override
void setToEnd() {
_timer = delay;
_child.setToEnd();
}
@override
void onMount(Effect parent) => _child.onMount(parent);
}
@henrique-marques-pre sorry for the late reply, do you want to create a PR with this fix? :)