首页 > 解决方案 > 在描述中描述的这种情况下如何返回登陆屏幕?

问题描述

我是新手,我有一个登录屏幕,在单击登录按钮时,我使用 pushReplacement 推送了一条路线(登陆屏幕)(因为我不想让用户点击返回按钮并再次进入登录屏幕),我的登陆页面由bottomNavigationBar组成,我希望我的bottomNavigtionBar一直在应用程序中持续存在,所以我决定使用persistent_bottom_nav_bar libaray。我的导航栏项目是(主页、搜索和设置),在我的主页navBarItem 子小部件上,我有一个名为“goToNextScreen”的按钮,当我按下“goToNextScreen”按钮时,我按下了一条新路线,现在在下一个屏幕上我只想拥有应用栏上的后退按钮,以便我可以再次回到我的主页 navbarItem 子小部件(登陆屏幕)。附上我的登陆屏幕以便更好地理解。

这是我的 NextScreen 页面

标签: flutterflutter-bottomnavigation

解决方案


要向 AppBar 添加后退按钮,您必须定义前导属性

一个小例子

AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        bottomOpacity: 0,
        shadowColor: Colors.transparent,
        leading: IconButton(
            icon: SvgPicture.asset(
                "assets/icons/arrow_back.svg",
                color: AppColors.currentAppTheme.boxBackgroundTextColor,
            ),
            onPressed: () {
                Navigator.pop(context);
            },
        ),
    );

推荐阅读