Flutter:如何从 ongenerate Route 注销?

Flutter: How to logout from ongenerate Route?

我在不更改 AppBar 和 TabBar 的情况下使用 Tabbar 和 onGenerateRoute 在一个屏幕上显示多个视图。

**

Here is my code(MainScreen Template)-

**

.....
....
  return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size(_width, 100),
        child: AppBar(
          automaticallyImplyLeading: false,
          backgroundColor: blue,
          bottom: PreferredSize(
            preferredSize: Size(_width, 40),
            child: Stack(
              children: [
                Center(
                  child: logoIcon(
                    75.0,
                    75.0,
                    Colors.white,
                  ),
                ),
                Positioned(
                  right: 15.0,
                  child: IconButton(
                      icon: Icon(
                        Icons.notifications_none,
                        color: Colors.white,
                        size: 32.0,
                      ),
                      onPressed: () {}),
                )
              ],
            ),
          ),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.vertical(
              bottom: Radius.circular(50),
            ),
          ),
        ),
      ),
      body: CustomMainBody(
        child: Container(
          height: _height * 0.90,
          width: _width,
          child: TabBarView(
            controller: _tabController,
            children: [
              Navigator(
                onGenerateRoute: (settings) => MaterialPageRoute(
                  builder: (context) => HomePage(
                      changeTabCallBack: (index) => changeTabbar(index)),
                  settings: settings,
                ),
              ),
              Navigator(
                onGenerateRoute: (settings) => MaterialPageRoute(
                  builder: (context) => RateComparision(),
                  settings: settings,
                ),
              ),
              Navigator(
                onGenerateRoute: (settings) => MaterialPageRoute(
                  builder: (context) => DealOffers(),
                  settings: settings,
                ),
              ),
              Navigator(
                onGenerateRoute: (settings) => MaterialPageRoute(
                  builder: (context) => CustomDrawer(
                      changeTabCallBack: (index) => changeTabbar(index)),
                  settings: settings,
                ),
              ),
            ],
          ),
        ),
      ),
      bottomNavigationBar: Container(
        color: blue,
        child: TabBar(
          indicatorColor: Colors.white,
          labelColor: Colors.black,
          controller: _tabController,
          tabs: [
            Tab(
              child: Image.asset(
                "assets/images/home-nav.png",
                color: Colors.white,
                height: 26,
                width: 26,
              ),
            ),
            Tab(
              child: Image.asset(
                "assets/images/rate-nav.png",
                color: Colors.white,
                height: 26,
                width: 26,
              ),
            ),
            Tab(
              child: Image.asset(
                "assets/images/OffersNavigation.png",
                color: Colors.white,
                height: 26,
                width: 26,
              ),
            ),
            Tab(
              child: Icon(
                Icons.menu,
                color: Colors.white,
                size: 32.0,
              ),
            ),
          ],
        ),
      ),
    );

自定义抽屉页面中,我添加了一个注销项。但是当我通过注销功能进入登录界面时,AppBar和TabBar并没有消失(主界面模板留在这里)。

我该如何解决这个问题?

在主屏幕模板上创建回调

  void logout() {
    Navigator.of(context)
        .push(CupertinoPageRoute(builder: (context) => LoginScreen()));
  }

传递值并从抽屉注销按钮调用它