I have a flutter app that have a tab bar , I have the widgets in tab B set to keepAlive when i swipe to tab A i want to dispose them or set there wantToKeepAlive property to false . All this because it's expensive to not keep them allaive when viewing tab B and if I keep them allive in tab A i will rebuild them in the background making tab A lag
I tried to make a bool in my provider and used it in the wantKeepAlive property of the widget but it's not working , it won't react to changes in the bool from provider bool get wantKeepAlive => Provider.of<Lists>(context, listen: false).keepAlive;
sorry for mistakes it's my first time asking.
here is my code for the tabbar and tabbarView:
List<Widget> tabs = [
const Tab(
icon: Icon(Icons.monetization_on_outlined),
),
const Tab(
icon: Icon(Icons.stacked_line_chart_rounded),
)
];
TabBar(
tabs: tabs,
unselectedLabelColor: Colors.grey,
labelColor: Colors.white,
indicatorColor: Colors.white,
indicatorSize: TabBarIndicatorSize.label,
),
),
const Expanded(
child: TabBarView(
children: [SellPage(), StatsPage()],
),
),
and this is simplfied 'StatsPage()':
class StatPage extends StatelessWidget {
const StatPage({super.key});
@override
Widget build(BuildContext context) {
return Flex(direction: Axis.vertical,children: [
FirstChart(),
SexondChart(),
ThirdChart(),
],);
}
}
what I want to do is to keep this three charts allive when the user is on the stats tab and kill them when he is in the sales tab or any other place in the app.