From 475c6b884b7f4611c54b04114e2765b34b753f8c Mon Sep 17 00:00:00 2001 From: mhstoller <36415486+mhstoller@users.noreply.github.com> Date: Sun, 20 Jun 2021 17:46:25 -0400 Subject: [PATCH 1/3] Enable dynamic wave amplitude adjustments This change allows the WaveWidget's waveAmplitude property to be updated dynamically (such as in a StreamBuilder) to change the amplitude on the fly --- lib/wave.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/wave.dart b/lib/wave.dart index 51d97f7..472abd7 100644 --- a/lib/wave.dart +++ b/lib/wave.dart @@ -341,6 +341,20 @@ class _WaveWidgetState extends State with TickerProviderStateMixin { _endAnimationTimer?.cancel(); super.dispose(); } + + @override + void didUpdateWidget(covariant WaveWidget oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.waveAmplitude != widget.waveAmplitude) { + setState(() { + for (int i = 0; + i < (widget.config as CustomConfig).durations.length; + i++) { + _waveAmplitudes[i] = widget.waveAmplitude + 10; + } + }); + } + } @override Widget build(BuildContext context) { From 2a89e4d0422c8413d1b792134992d87f65e4fd21 Mon Sep 17 00:00:00 2001 From: mhstoller <36415486+mhstoller@users.noreply.github.com> Date: Sun, 20 Jun 2021 17:55:30 -0400 Subject: [PATCH 2/3] idk about null safety rip --- lib/wave.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wave.dart b/lib/wave.dart index 472abd7..3cf9749 100644 --- a/lib/wave.dart +++ b/lib/wave.dart @@ -348,7 +348,7 @@ class _WaveWidgetState extends State with TickerProviderStateMixin { if (oldWidget.waveAmplitude != widget.waveAmplitude) { setState(() { for (int i = 0; - i < (widget.config as CustomConfig).durations.length; + i < (widget.config as CustomConfig).durations?.length; i++) { _waveAmplitudes[i] = widget.waveAmplitude + 10; } From 002c5f0404bdb0324ce06327e8adc6004e5862f1 Mon Sep 17 00:00:00 2001 From: mhstoller <36415486+mhstoller@users.noreply.github.com> Date: Sun, 20 Jun 2021 18:16:42 -0400 Subject: [PATCH 3/3] null safety, but hopefully its right this time I haven't migrated my project to null safety so I was just kind of guessing what it wanted when a build error occured --- lib/wave.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wave.dart b/lib/wave.dart index 3cf9749..439fecb 100644 --- a/lib/wave.dart +++ b/lib/wave.dart @@ -348,7 +348,7 @@ class _WaveWidgetState extends State with TickerProviderStateMixin { if (oldWidget.waveAmplitude != widget.waveAmplitude) { setState(() { for (int i = 0; - i < (widget.config as CustomConfig).durations?.length; + i < (widget.config as CustomConfig).durations!.length; i++) { _waveAmplitudes[i] = widget.waveAmplitude + 10; }