繁体   English   中英

用户无法在 firebase Flutter 应用程序中注销

[英]User not able to sign out in firebase Flutter application

D/FirebaseAuth(7994):通知 id 令牌侦听器有关注销事件。 D/FirebaseAuth(7994):通知身份验证 state 侦听器有关注销事件。

class LandingPage extends StatefulWidget {
  @override
  _LandingPageState createState() => _LandingPageState();
}

class _LandingPageState extends State<LandingPage> {
  User _user;

  @override
  void initState() {
    super.initState();
    _updateUser(FirebaseAuth.instance.currentUser);
  }
  void _updateUser(User user) {
    setState(() {
      _user = user;
    });
  }

  @override
  Widget build(BuildContext context) {
    if (_user == null) {
      return SignInPage(
        onSignIn: _updateUser,
      );
    }
    return HomePage(
      onSignOut: () => _updateUser(null),
    );
  }
}

主页代码:-

class HomePage extends StatelessWidget {

  HomePage({@required this.onSignOut});
  final VoidCallback onSignOut;
  Future<void> _signOut() async {

    try {
      await FirebaseAuth.instance.signOut();
    } catch (e) {
      print(e.toString()) ;
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home Page'),
        actions: <Widget>[
          FlatButton(
            child: Text(
              'Logout',
              style: TextStyle(
                  fontSize: 18.0,
                  color: Colors.white,
              ),
            ),
            onPressed: _signOut,

          ),
        ],
      ),
    );
  }
}

这是我的代码,但用户无法退出我的应用程序。有人可以告诉我要修复什么吗

尝试等待signout呼叫:

class HomePage extends StatelessWidget {

  HomePage({@required this.onSignOut});
  final VoidCallback onSignOut;
  Future<void> _signOut() async {    
    try {
      await FirebaseAuth.instance.signOut();
    } catch (e) {
      print(e.toString()) ;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home Page'),
        actions: <Widget>[
          FlatButton(
            child: Text(
              'Logout',
              style: TextStyle(
                  fontSize: 18.0,
                  color: Colors.white,
              ),
            ),
            onPressed: () async => await _signOut(), // Updated code    
          ),
        ],
      ),
    );
  }
}

暂无
暂无

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

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