How to Signout a user in Flutter with Firebase authentication

前端 未结 5 731
我在风中等你
我在风中等你 2021-01-03 19:52

I have a problem signing out the current user from my app

the method I am using is as follows:

....
onPressed:_signOut
//jump to function


  void _s         


        
5条回答
  •  庸人自扰
    2021-01-03 20:23

    First create an instance of FirebaseAuth like so

     FirebaseAuth auth = FirebaseAuth.instance;
    

    Then add this to either your logout button or any means you wish to use for the logout.

    signOut() async {
        await auth.signOut();
      }
    

    You can also create a function and then call the signOut within your button like so

    import 'package:flutter/material.dart';
    
    class SignOut extends StatefulWidget {
      @override
      _ SignOut State createState() => _ SignOut State();
    }
    
    class _ SignOut State extends State< SignOut > {
    
         FirebaseAuth auth = FirebaseAuth.instance;
        
          signOut() async {
            await _firebaseAuth.signOut();
          }
        
          @override
          Widget build(BuildContext context) {
            return Scaffold(
              backgroundColor: Colors.white,
              body: Center(
                child: Container(
                  child: RaisedButton(
                    onPressed: () {
                      signOut();
                    },
        
                  )
                ),
              ),
            );
          }
        }
    

    You decide.

提交回复
热议问题