5

I'm developing with reactive components streams/observables with Rx_command, Rx_dart

Problem:

  • In my Flutter app I have inherited widget that can be called anywhere with:

    FooProvider.of(context).foo.method1...

  • I need to make a first call to the method when the UI loads at first time

  • I can't use init.state because it's impossible
  • I use didchangedependencies it works but..

    ... every time the ui reloads, the didchangedependencies is called and the method is executed once again.

I don't want it to be executed and I can't use init.state

How can execute the method only once?

Paulo Bruckmann
  • 331
  • 4
  • 7

1 Answers1

3

Instead of context.inheritFromWidgetOfExactType, use context.ancestorInheritedElementForWidgetOfExactType

final myInherited = context.ancestorInheritedElementForWidgetOfExactType(MyInherited)?.widget;

This method is available inside initState

Rémi Rousselet
  • 256,336
  • 79
  • 519
  • 432