I have an issue with my app, the thing is that I have an app with 3 tabs:
@override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
body: DefaultTabController(
length: 3,
child: _isLoading ? Center(
child: CircularProgressIndicator()
)
: Scaffold(
bottomNavigationBar: Material (
child: TabBar(
tabs: <Tab>[
Tab(icon: Icon(Icons.add_shopping_cart)),
Tab(icon: Icon(Icons.shopping_basket)),
Tab(icon: Icon(Icons.person)),
],
),
color: Colors.green,
),
body: TabBarView(
children: [
ProductListPage(),
OrderPage(),
InfoPage(),
],
),
),
)
),
onWillPop: onBackPressed
);
}
And in every children page, I implement onInit
to load datas from Backend:
/* The exact same thing in ProductListPage, OrderPage and InfoPage */
@override
void initState() {
_isLoading = true;
onInit().then((value) {
print('initStateProductList');
});
super.initState();
}
But the issue is when I swipe page on TabBarView
, I don't understand why, but sometimes when I swipe from first tab to tab 3, the app is calling InitState
from tab 2:
The same thing when I swipe from Tab3 to Tab1, I found a workaround with AutomaticKeepAliveClientMixin
but I don't like it because I want to reload everytime I swipe.
you are implementing this on parent
_isLoading ? Center(
child: CircularProgressIndicator()
)
just leave it to your children this are the tab
children: [
ProductListPage(),
OrderPage(),
InfoPage(),
],
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.