[英]My app is calling all TabBarView contents when I swipe
I have an issue with my app, the thing is that I have an app with 3 tabs:我的应用程序有问题,问题是我有一个带有 3 个选项卡的应用程序:
@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:在每个子页面中,我实现了onInit
从后端加载数据:
/* 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:但问题是当我在TabBarView
上滑动页面时,我不明白为什么,但有时当我从第一个选项卡滑动到选项卡 3 时,应用程序正在从选项卡 2 调用InitState
:
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.当我从 Tab3 滑动到 Tab1 时,我发现了一个解决方法AutomaticKeepAliveClientMixin
但我不喜欢它,因为我每次滑动时都想重新加载。
you are implementing this on parent你正在父母身上实施这个
_isLoading ? Center(
child: CircularProgressIndicator()
)
just leave it to your children this are the tab把它留给你的孩子,这是标签
children: [
ProductListPage(),
OrderPage(),
InfoPage(),
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.