1

So I have a Widget and inside the build method:

Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, constraint) {
      return Container(
        child: GestureDetector(
            behavior: HitTestBehavior.translucent,
            child: swipeTile),
      );
    });
  }

When I call setState in another function the Widget wont update. It will still show the old "swipeTile".

void newSwipeTile(int swipeDirection) {
    swipeTile.tile.disposeAnim();
    setState(() {
      this.swipeDirection = swipeDirection;
      this.round++;
      this.swipeTile = new SwipeTile(size: 40);
    });
  }

I already tried using a Container and asigning an Unique Key to it with the swipe tile as a child. That acutally worked but then I got this error message: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4606 pos 12: '_state._element == null': is not true.

child: Container(
          key: UniqueKey(),
          child: swipeTile,
       )
Quasi
  • 576
  • 4
  • 13
  • What does this `disposeAnim();`. Did you tried to call this dispose after the setState? – JRamos29 Jun 27 '20 at 22:34
  • It just disposes the AnimationController in the SwipeTile class. Its a custom class. Still removing it doesnt do anything. I can literally use a Stack with a Container and my custom SwipeTile class, and if I cange the Container and the SwipeTile, only the Container will change. – Quasi Jun 27 '20 at 22:41
  • What class do you instantiate to call newSwipeTile() method? – JRamos29 Jun 27 '20 at 22:47
  • Its in the same class as the build Method. I removed the onTap method on Stackoverflow to make everything shorter: `onTap: (){ newSwipeTile(1); }` – Quasi Jun 27 '20 at 22:52
  • Out of curiosity, did you tried to remove the `this.` statement from the three lines inside the set state? Cause int this context, i believe that `this` refers to the State class of your stateful widget, and maybe this is what causing the error message that you reported. – JRamos29 Jun 27 '20 at 22:56
  • Thx this worked. But I got a few new Errors so I had to rebuild everything. – Quasi Jun 28 '20 at 00:19
  • Nice. It's alright. – JRamos29 Jun 28 '20 at 00:26

0 Answers0