Query DocumentFromReference in component in a swipeableStack - Glitch

Troubleshooting

Hello, I have a small issue, and i would like to know you opinions.

I have a swipeableStack and in it I have a component.

In this component I do a query Document From reference. So the only parameter for this component is a Reference Document.

And in the swipe I have a Generating Children from variable (output of a custom action)

So I was thinking I was super smart to only get the refernece document and not the whole document (I was thinking that probably need to fetch less data ? more clean ? I don't know I did like that)

And as I said in my compenent i fetch the data of the document with the query.

Everything works pretty well execpt a small detail. When I swipe my card, till i hold the first card, can see the second card behind with all the correct data, that is fine. But as soon as I swipe the first car (so the card disappeared from the page, there is like a glitch, the second page "reload" the data so during 0.1s the 2nd card disappear and comes back.

I don't really understand because before to remove the first card, i can clearly see the second card behind (so the data are already there), but for some reason the app reload the card.

In the console i have this error :

Uncaught DartError: Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method. 

I believe it's this the issue.

I asked gpt and he said i should just change that part

@override
void dispose() {
  final parent = context.findAncestorWidgetOfExactType<MyParentWidget>();
  super.dispose();
}

to that

MyParentWidget? _parentWidget;

@override
void didChangeDependencies() {
  super.didChangeDependencies();
  // Enregistre la référence au parent ici
  _parentWidget = context.dependOnInheritedWidgetOfExactType<MyParentWidget>();
}

@override
void dispose() {
  // Utilise la référence sauvegardée au lieu d'accéder à l'ancestor via le context
  if (_parentWidget != null) {
    // Exécuter le code lié au parent ici
  }
  super.dispose();
}

But looks like natively in FF we cannot touch the dispose.

To avoid this issue I could simply fetch the whole data instead of the documentReference and pass the document in my component. and i guess no more issue because no more backend query in my component.

But do you think I have to do that or it's better/cleaner to keep only the documentreference and do what gpt said ? (i don't even know if that will fix the problem)

But once again i don't get why the app reload the 2page, because in the swipe as setting i have 2 Card display count, so he load all the data there I guess.

Thank you for you help

What have you tried so far?

.

Did you check FlutterFlow's Documentation for this topic?
Yes