Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob.animatedRandom duration doesn't update #12

Open
anaurelian opened this issue Oct 13, 2021 · 0 comments
Open

Blob.animatedRandom duration doesn't update #12

anaurelian opened this issue Oct 13, 2021 · 0 comments

Comments

@anaurelian
Copy link

When using Blob.animatedRandom, the duration of the animated blob seems to be stuck to the initial value, even if it is changed using setState in a StatefulWidget.

Here is the test app running on an Android 11.0 (API 30) emulator. Pressing the FAB button assigns a random duration and a random color. So the duration keeps changing (as reflected in the app bar), but the animation of the blob shape doesn't seem to change its rythm:

blobs_duration_test_2.mp4
...

class _HomeScreenState extends State<HomeScreen> {
  final Random _random = Random();
  Color _color = Colors.blueGrey;

  // The duration of the animated blob seems to be stuck to this initial value, even if we change it using setState.
  int _duration = 500;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Duration: $_duration milliseconds'), // display the current duration
      ),
      body: Blob.animatedRandom(
        size: 400,
        edgesCount: 6,
        minGrowth: 7,
        // Apply the current color - this works.
        styles: BlobStyles(color: _color),
        loop: true,
        // Apply the current duration - doesn't seem to work!
        duration: Duration(milliseconds: _duration),
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.shuffle),
        onPressed: () => setState(() {
          // Randomize the duration and the color
          _duration = _random.nextInt(20) * 500;
          _color = Color.fromRGBO(_random.nextInt(256), _random.nextInt(256), _random.nextInt(256), 1.0);
        }),
      ),
    );
  }
}

(See the full code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant