2

The problem is, I need to call method after widget is built, otherwise I'm getting an error. So I want to know is there a way to check whether widget is built, maybe a listener?

Mayde
  • 143
  • 1
  • 2
  • 8
  • As @Ampersanda stated this could be a duplicate, anyhow what you should do is make that widget `stateful` and override the `initState` method. – Ethan K Jan 07 '20 at 11:50
  • Does this answer your question? [Flutter: Run method on Widget build complete](https://stackoverflow.com/questions/49466556/flutter-run-method-on-widget-build-complete) – Ampersanda Jan 07 '20 at 11:52

1 Answers1

10

All widgets have a bool this.mounted property. It turns true when the buildContext is assigned.

Tip: Its a good practice to set the state of any widget only after the widget is built and I usually use this bool to set states once it is true. It is an error to call setState when a widget is unmounted or before it is mounted.

In your case, I feel you need the same thing, run your method if this.mounted == true.

Yudhishthir Singh
  • 2,941
  • 2
  • 23
  • 42