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

text with setState not work #27

Closed
leapit opened this issue May 10, 2019 · 5 comments
Closed

text with setState not work #27

leapit opened this issue May 10, 2019 · 5 comments

Comments

@leapit
Copy link

leapit commented May 10, 2019

text with setState not work

code like this

setState(() {
  text = ["AWESOME", "OPTIMISTIC", "DIFFERENT"];
});

.....

RotateAnimatedTextKit(
      text: text,
    ),

When text state change

setState(() {
  text = ["A", "B", "C","D","E"];
});

will got error

I/flutter (10175): The following RangeError was thrown building AnimatedBuilder(animation: AnimationController#386c6(⏭
I/flutter (10175): 1.000; paused), dirty, state: _AnimatedState#4fb90):
I/flutter (10175): RangeError (index): Invalid value: Not in range ...

Flutter:

[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.13.6 17G6030, locale en-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.4)
[✓] VS Code (version 1.33.1)
[✓] Connected device (1 available)
@leapit leapit changed the title text in setState not work text with setState not work May 10, 2019
@aagarwal1012
Copy link
Owner

@leapit, any updates regarding this issue?

@aagarwal1012
Copy link
Owner

Since there is no reply coming from @leapit, I am closing this issue. Please feel free to reopen it if any problem exists.

@ebeyabraham
Copy link

ebeyabraham commented Jul 20, 2020

@aagarwal1012 Facing the same issue. I am unable to update the animated text using setState method.

Widget build(context) {

    Widget dynamicResponse = Container(
      padding: const EdgeInsets.all(32),
      child: TyperAnimatedTextKit(
        isRepeatingAnimation: false,
        text: [
          responseText,
        ],
      ),
    );

    return Scaffold(
      body: ListView(
        children: [
          dynamicResponse
        ],
      ),
    );

   updateText() {
    setState(() {
      responseText = newValue();
    });
  }

updateText updates the value to responseText but the changes are not reflected to the widget.

@mohsin2596
Copy link

For anyone who is still getting the issue ... make sure you pass in a ValueKey as the key to your TyperAnimatedTextKit ... then when you would setState it would update the widget for you

@JesusJoseph
Copy link

This solution works perfectly for flutter projects using GetX package using Obx instead of setState.

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

5 participants