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

AniationAsWidget does not update after setting state #73

Closed
alefcarlos opened this issue Apr 6, 2019 · 5 comments
Closed

AniationAsWidget does not update after setting state #73

alefcarlos opened this issue Apr 6, 2019 · 5 comments
Assignees
Labels

Comments

@alefcarlos
Copy link

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.4.10, on Mac OS X 10.14.4 18E226, locale pt-BR)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2)
[✓] Android Studio (version 3.3)
[✓] VS Code (version 1.33.0)
[✓] Connected device (1 available)

After upgrading to version 0.10.3, animationAsWidget is not updating the animation. It was working in previous version.
@renancaraujo has fixed this, but with 0.10.3 release it is broken again.

I've created a StatelessWidget to show current Sprit:

class PokemonAnimation extends StatelessWidget {
  final int number;
  PokemonAnimation({Key key, @required this.number}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Flame.util.animationAsWidget(
      Position(100.0, 100.0),
      animation.Animation.sequenced('1-generation.png', 2,
          textureX: PokemonPostision.fromNumber(number).imageX,
          textureY: PokemonPostision.fromNumber(number).imageY,
          textureHeight: PokemonPostision.height,
          textureWidth: PokemonPostision.width,
          stepTime: 0.2),
    );
  }
}

.. and the StatefullWidget:

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int poke;

  void initState() {
    super.initState();
    poke = 1;
  }

  void plusPoke() {
    setState(() {
      poke++;
    });
  }

  void minusPoke() {
    setState(() {
      var result = poke - 1;
      if (result <= 0) result = 1;

      poke = result;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text('Pokédex Fire Red/Leaf Green'),
        centerTitle: true,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              RaisedButton(
                child: Icon(
                  Icons.navigate_before,
                  size: 20.0,
                ),
                onPressed: minusPoke,
              ),
              RaisedButton(
                child: Icon(
                  Icons.navigate_next,
                  size: 20.0,
                ),
                onPressed: plusPoke,
              ),
            ],
          ),
          PokemonAnimation(number: poke),
          Text('#$poke')
        ],
      ),
    );
  }
}

Source code is available here

Thanks !

@erickzanardo
Copy link
Member

@renancaraujo are you able to take a look on this?

@renancaraujo
Copy link
Member

Looking into it now

@renancaraujo renancaraujo self-assigned this Apr 8, 2019
@erickzanardo
Copy link
Member

News on this @renancaraujo ?

@renancaraujo
Copy link
Member

I was look in the wrong place. Thats why it took this long. Solution in #78.

@luanpotter
Copy link
Member

Merged.

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

No branches or pull requests

4 participants