简体   繁体   English

我如何更改用户 state flutter 的抽屉项目

[英]how can i change drawer items on user state flutter

how can i change the drawer items on flutter depending on the user state the drawer has 2 items sign in and sign out and when i press sign out the user signed out but the drawer dose not change the log out button still visible and i should reload the page so its disappear and the sign in button appears如何根据用户 state 更改 flutter 上的抽屉项目,抽屉有 2 个项目登录和注销,当我按下注销时,用户已注销,但抽屉不会更改注销按钮仍然可见,我应该重新加载页面因此消失并出现登录按钮

if (_auth.currentUser == null)
                Column(
                  children: [
                    ListTile(
                      title: Text('Sign In'),
                      onTap: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => SignIn()),
                        );
                      },
                    ),
                  ],
                )
              else
                Column(
                  children: [
                    ListTile(
                      title: Text('My Cars'),
                      onTap: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => MyCars()),
                        );
                      },
                    ),
                    ListTile(
                      title: Text('Sign Out'),
                      onTap: () {
                        signOut();
                        
                      },
                    ),
                  ],
                ),

also the sign in has navigation function that navigate to the screen that has the drawer but when this happen the the drawer is still show the sign in button and i should navigate again to change it登录也有导航 function 导航到有抽屉的屏幕但是当这种情况发生时抽屉仍然显示登录按钮,我应该再次导航以更改它

wrap listile into the visibility widget,将 listile 包装到visibility小部件中,

Visibility (
    visible: _visible
    child: ListTile(...)
);

declare a boolean variable _visible and set it's value.声明一个 boolean 变量_visible并设置它的值。 you can check all condition and make it true false in setState to hide and show ListTile .您可以检查所有条件并在setState中将其设为 true 以隐藏和显示ListTile

setState(() {
    _visible = false;
});

setState(() {
    _visible = true;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM