简体   繁体   English

当我滑动时,我的应用程序正在调用所有 TabBarView 内容

[英]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

在这张图片中,我从 Tab1 滑动到 Tab3

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.

相关问题 如何检测我的应用何时通过滑动终止? - How to detect when my app is terminated with a swipe? 当我从左向右滑动时,如何禁止我的 Wear OS 应用程序关闭? - How can I disable that my Wear OS app closes when I swipe from left to right? 当我刷出我的应用程序(在其他进程中运行)时,运行在单独进程上的 Android 服务被杀死 - Android Service running on separate Process gets killed when I swipe out my App (running in other process) 当我从一个片段滑动到另一个片段时,我的应用程序崩溃(错误:canScrollHorizo​​ntally()&#39; 在空对象引用上) - my app crashes when I swipe from one fragment to another (error: canScrollHorizontally()' on a null object reference) 每当我在色轮外滑动时,我的应用程序就会崩溃 - my app crashes whenever i swipe outside the color wheel 运行proguard时,是否可以只用一句话就将jar文件中的所有内容都保留? - Can I keep all the contents in my jar file in just one sentence when I run proguard? 我想使用滑动技术在我的应用程序中实现解锁。 - I want to use swipe technique to implement unlocking in my app. 如何在我的 WebVIew 应用程序中添加滑动刷新? - How can i add Swipe to Refresh in my WebVIew app? 调用动画时我的应用程序崩溃了吗? - My App Crashes when calling my Animation? 如何在 flutter 中实现 TabBarView 滑动刷新? - How to implement TabBarView with swipe to refresh in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM