marcglasberg / async_redux

Flutter Package: A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.
Other
230 stars 41 forks source link

How I can active onDidChange after onInit? #73

Closed LeandroMoura3 closed 4 years ago

LeandroMoura3 commented 4 years ago

I wanna show a dialog when the page is loaded. But if I call the dialog in onInit, this don't works. If I call the dialog in onDidChange, this don't are called on start of page. But in Flutter StatefulWidget, the didChangeDependencies are called after the page start, and in it I can put the dialog call.

Because that, I will need to put a StatefulWidget only for it. Have any way to do it with storeconnectors?

Thanks.

LeandroMoura3 commented 4 years ago

Oh, when I put the call of dialog in a Future.delayed with zero of duration, that's works!

'Future.delayed(Duration.zero, () async { waitingDialog(context); await ...myAsyncWorks });'

I think that not more sophisticated way, but my problem are solved. I think that issues can close, but if you have a better solution for it, reopen.

Thanks.

marcglasberg commented 4 years ago

You should probably use this instead of Future.delayed:

  SchedulerBinding.instance.addPostFrameCallback((_) {
    waitingDialog(context);
    await ...myAsyncWorks
  });

Or you can use this package: https://pub.dev/packages/after_layout

Você é brasileiro ou português? Se sim, pode falar comigo em português. Abs.

LeandroMoura3 commented 4 years ago

Sim, hehehe.

Agradeço pela atenção.

Abs.