onResume() and onPause() for widgets on Flutter

后端 未结 4 1151
故里飘歌
故里飘歌 2020-12-08 10:04

Right now, a widget only has initeState() that gets triggered the very first time a widget is created, and dispose(), which gets triggered when the widget is destroyed. Is t

4条回答
  •  半阙折子戏
    2020-12-08 10:52

    I am a little late but came with perfect solution for those who may be looking for it in the future. the Navigator.push() is actually a Future. it means it has then() callback function. so the then() will be called after you call Navigator.pop() from the second screen. and even you can send some data from the second screen and access the data in the first screen.

    example:

    //from Screen A
    Navigator.of(context).push(MaterialPageRoute(builder:(context)=>B()))
    .then((value)=>{ refresh() });
    
    //in Screen B with data
    Navigator.pop(context,[1]);
    
    //or without data
    Navigator.pop(context);
    

    so refresh() will be called on resume of Screen A.

提交回复
热议问题