使用這個(gè) AutomaticKeepAliveClientMixin 的時(shí)候?yàn)榱吮3挚刂破鞯臓顟B(tài)但是有時(shí)候這個(gè)是無(wú)效的
正常的你在你的控制器里面這樣設(shè)置
class _TaskState extends State<Task> with AutomaticKeepAliveClientMixin{
@override
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
super.build(context);
}
}
我也是這樣設(shè)置的但是毫無(wú)軟用,我找了好久發(fā)現(xiàn)這樣設(shè)置應(yīng)該是對(duì)的
你可以去上面的一層控制器找找原因,tabbar 控制器里面
度娘之后找到原因
body: vcs[context.watch<Counter>().value] //AutomaticKeepAliveClientMixin要配合IndexedStack使用才有效
請(qǐng)把你的tabbar的切換改成這樣
body: IndexedStack(
index: context.watch<Counter>().value, //我這邊使用了Provide管理了index
children: vcs,
),