【问题标题】:Flutter: How to logout from ongenerate Route?Flutter:如何从ongenerate Route注销?
【发布时间】:2021-05-07 16:43:41
【问题描述】:

我在一个屏幕中使用 Tabbar 和 onGenerateRoute 进行多个视图,而无需更改 AppBar 和 TabBar。

**

这是我的代码(MainScreen 模板)-

**

.....
....
  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并没有消失(主屏幕模板留在这里)。

我该如何解决这个问题?

【问题讨论】:

    标签: flutter routes tabbar


    【解决方案1】:

    在主屏幕模板上创建回调

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

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

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 1970-01-01
      • 2021-01-24
      • 2017-12-31
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-30
      相关资源
      最近更新 更多