Home > database >  When AutomaticKeepAliveClientMixin Widget is back on screen, how to refresh it?
When AutomaticKeepAliveClientMixin Widget is back on screen, how to refresh it?

Time:09-09

I have a tab page with AutomaticKeepAliveClientMixin, which works well.

What I want is, when switch back to this page, I can choose refresh this page or not.

As far as I know, wantKeepAlive seems work on when widget is displayed.

I also checked life cycle of State. Method like initState, activate. None of them worked.

So my question is, Will there be any thing triggered when AutomaticKeepAliveClientMixin Widget is back on screen?

Or if AutomaticKeepAliveClientMixin can't do that, is there any other way to keep page state, and

CodePudding user response:

Navigator.pop(context, false);

you can use this on screen

when you send to new screen

    final return = Navigator.of(context).push(MaterialPageRoute<bool>());
if(return){
//
}else{
//
}

CodePudding user response:

Move the state up from the page (tab) to parent and initiate refresh in onTap of TabBar.

TabBar(
  onTap: (index) {
    // TODO
  },
  controller: _controller,
  tabs: const <Widget>[
    ...
  ],
),

For a more elegant solution take a look at Simple app state management.

  • Related