diff --git a/fireworks/lib/src/foundation/controller.dart b/fireworks/lib/src/foundation/controller.dart index 1a0575b..3a0d692 100644 --- a/fireworks/lib/src/foundation/controller.dart +++ b/fireworks/lib/src/foundation/controller.dart @@ -63,6 +63,7 @@ class FireworkController implements Listenable { double _globalHue = 42; late final Ticker _ticker; + var _paused = false; /// Starts the firework show. /// @@ -74,6 +75,22 @@ class FireworkController implements Listenable { _ticker = vsync.createTicker(_update)..start(); } + /// Pauses the firework show. + /// + /// Can only be called while the firework show is running. + void pause() { + assert(!_paused); + _paused = true; + } + + /// Resumes the firework show. + /// + /// Can only be called while the firework show is paused. + void resume() { + assert(_paused); + _paused = false; + } + final List _listeners; @override @@ -127,6 +144,8 @@ class FireworkController implements Listenable { Duration _lastRocketSpawn = Duration.zero; void _update(Duration elapsedDuration) { + if (_paused) return; + if (windowSize == Size.zero) { // We need to wait until we have the size. return; diff --git a/fireworks_demo/lib/main.dart b/fireworks_demo/lib/main.dart index 3b741f1..3f46464 100644 --- a/fireworks_demo/lib/main.dart +++ b/fireworks_demo/lib/main.dart @@ -55,6 +55,7 @@ class _FireworksState extends State<_Fireworks> ); var _showInfoOverlay = false; + var _isPaused = false; @override void dispose() { @@ -75,6 +76,16 @@ class _FireworksState extends State<_Fireworks> _showInfoOverlay = !_showInfoOverlay; }); }, + onSecondaryTap: () { + setState(() { + _isPaused = !_isPaused; + if (!_isPaused) { + _controller.pause(); + } else { + _controller.resume(); + } + }); + }, child: Stack( children: [ Fireworks( @@ -151,6 +162,7 @@ class _FireworksState extends State<_Fireworks> Text( 'Hover with your mouse to launch fireworks to ' 'your mouse :)\n' + 'Right click to pause/resume the animation.\n' 'Or just lean back and enjoy the show (:\n\n' 'Click again to close this.', textAlign: TextAlign.center, diff --git a/fireworks_demo/pubspec.lock b/fireworks_demo/pubspec.lock index 7daa699..faaa7ab 100644 --- a/fireworks_demo/pubspec.lock +++ b/fireworks_demo/pubspec.lock @@ -17,13 +17,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" collection: dependency: transitive description: @@ -89,13 +82,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.4" material_color_utilities: dependency: transitive description: