使用這個 AutomaticKeepAliveClientMixin 的時候為了保持控制器的狀態(tài)但是有時候這個是無效的
正常的你在你的控制器里面這樣設(shè)置
class _TaskState extends State<Task> with AutomaticKeepAliveClientMixin{
@override
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
super.build(context);
}
}
我也是這樣設(shè)置的但是毫無軟用,我找了好久發(fā)現(xiàn)這樣設(shè)置應該是對的
你可以去上面的一層控制器找找原因突想,tabbar 控制器里面
度娘之后找到原因
body: vcs[context.watch<Counter>().value] //AutomaticKeepAliveClientMixin要配合IndexedStack使用才有效
請把你的tabbar的切換改成這樣
body: IndexedStack(
index: context.watch<Counter>().value, //我這邊使用了Provide管理了index
children: vcs,
),