AutomaticKeepAliveClientMixin doesn't work for PlatformTabScaffold on Android
Hey there,
I noticed that the PlatformTabScaffold's tab's bodies are being rebuilt upon changing tabs which can be frustrating.
Therefore, I tried mixing AutomaticKeepAliveClientMixin into the tab's body classes.
On iOS this works as expected but on Android it doesn't.
As per this thread, this is a known issue.
While the issue has still not been closed, this S.O. answer proposes a solution to the problem: wrapping the bodies in a PageView.
Therefore, I think it would be a good idea to implement this solution for the PlatformTabScaffold.
I had a look and from what I can see is that the solution in that S.O. link works well enough. I updated the example (https://github.com/stryder-dev/flutter_platform_widgets/blob/f976eeed38bc0ef60e8feb9da46eddafec0ef126/example/lib/tab_pages/basicTabbedPage.dart) with this. Should keep state across tabs. The example tab pages have an increment (and independent of each other) which state is kept across tabs
IOS automatically keeps state and has separate navigators for each tab - i used below and it works fine class _SecondScreenState extends State<SecondScreen> with AutomaticKeepAliveClientMixin<SecondScreen> { @override bool get wantKeepAlive => true;
@override Widget build(BuildContext context) { super.build(context);
I also use pageview for android rather than indexedStack as index stack loads all pages at once and if you have any future builders it will run them at load time - which is something you may not want.