What is the equivalent for `componentDidMount()` in Flutter What is the equivalent for `componentDidMount()` in Flutter dart dart

What is the equivalent for `componentDidMount()` in Flutter


use initState in Stateful widget.InitState is called when the stateful widget is first time painted. For ex

class _MyAppState extends State<MyApp> {  Future<Album> futureAlbum;  @override  void initState() {    super.initState();    futureAlbum = fetchAlbum();  }


You can do this in Flutter's initState.It gets called first when your widget tree is rendered.

Check the code below:

  @override  void initState() {    super.initState();  }

For more details on various things in React Native you wished to know in Flutter.See the link below: It is the official documentation of people coming to Flutter from a React Native background.

Documentation

I hope this helps.


When it comes to request data from the server, you may want to use FutureBuilder directly.

Sometimes widget build will trigger twice if you put states in initial of state improperly.

I prefer to put FutureBuilder into widget build scope and more clean and readable for me.