andrewpmoore / widget_and_text_animator

Flutter package to make animating transitions easy for widget and text sequences
MIT License
25 stars 5 forks source link

State mangement not working properly when individual widget is wrapped with WidgetAnimator #7

Open princesanjivy opened 1 year ago

princesanjivy commented 1 year ago

In the below, Row widget I've my custom widgets each have their own WidgetAnimator and the values used in each of them will be changed over a button press from another widget's onPressed call where I have placed the setState(() {});. Basically, the issue is state is not getting updated across these separate widgets. When I everything under one WidgetAnimator state gets changed but I don't that behaviour.

Row(
  children: [
    WidgetAnimator(
      incomingEffect: WidgetTransitionEffects.incomingScaleUp(
        delay: const Duration(milliseconds: 400),
        curve: Curves.easeInOut,
      ),
      child: PlayerCard(
        imageUrl: "assets/images/user.png",
        name: "You ($playerChose)",
        isAsset: true,
        showScore: true,
        scoreValue: scores[PlaySymbol.inNum(playerChose)]!,
      ),
    ),
    WidgetAnimator(
      incomingEffect: WidgetTransitionEffects.incomingScaleUp(
        delay: const Duration(milliseconds: 1200),
        curve: Curves.easeInOut,
      ),
      child: Text(
        "Round\n$round",
        style: GoogleFonts.hennyPenny(
          fontSize: defaultTextSize - 2,
          color: themeProvider.primaryColor,
        ),
        textAlign: TextAlign.center,
      ),
    ),
    WidgetAnimator(
      incomingEffect: WidgetTransitionEffects.incomingScaleUp(
        delay: const Duration(milliseconds: 400),
        curve: Curves.easeInOut,
      ),
      child: PlayerCard(
        imageUrl: "assets/images/ai.png",
        name: "AI ($aiChose)",
        isAsset: true,
        showScore: true,
        scoreValue: scores[PlaySymbol.inNum(aiChose)]!,
      ),
    ),
  ],
),

Also, I tried of using Provider package, wrapping up each of these with Consumer by, this method it's working but the code looks complicated and I believe there must be some other workaround for using setState.

Please let me know if you need entire page source for debugging this. BTW, this is an awesome package 🎉

Thanks, any help will be appreciated.

andrewpmoore commented 12 months ago

Have you tried putting a Key onto the child widgets of the WidgetAnimator such as PlayerCard ? The class works similar to AnimatedSwitcher so it'll only detect changes to the child if the child is either of a different type (e.g. one is Text and one is Container) or if the key of the widget changes

giantss commented 6 months ago

I also encountered the same problem. The state of the Text wrapped by WidgetAnimator will not be refreshed. @andrewpmoore

andrewpmoore commented 6 months ago

@giantss I think at the moment it won't refresh the lower level widgets unless the key has changed on the child of the WidgetAnimator as it won't know there's been a change otherwise. It's something when I get some free time I'd like to look into trying to improve

giantss commented 6 months ago

@andrewpmoore

Okay, sorry to trouble you, waiting for the update. This time the plugin is great. At present, I can only set WidgetAnimator to UniqueKey to deal with it temporarily, but this will have a certain impact on performance.

giantss commented 5 months ago

@andrewpmoore

Hello, is there still time to fix this problem?

I use this plug-in in more and more places in my projects, and most of them are used in lists. If I keep using UniqueKey to solve the refresh problem, I am worried that there will be big problems in performance.

giantss commented 4 months ago

I also discovered a situation today. If you use WidgetAnimator as part of the list and click the component wrapped by WidgetAnimator to enter the next interface after the list is refreshed, the parameters passed in have changed, but the actual data is still the old data.

Currently I still use key UniqueKey to solve this problem. Can this issue be fixed soon?