Flutter App with Firebase

Mercy Jemosop
2 min readAug 6, 2021

--

Integrate Firebase with login and registration.

Follow this tutorial to setup your project with Firebase.

Registration

createUserWithEmailAndPassword(), is a function that is used to create a new account in Firebase using email and password.

N.B There are many other sign-in options.

This method creates a new user account, if it does not exist and automatically sign-in the user into the new account.

N.B a new account can only be created with a valid password(6 or more characters).

UserCredential class, this class is returned from an authentication request i.e in our case createUserWithEmailAndPassword. User class is returned as part of a usercredential when using authentication method.

FirebaseAuth, this is the entry point for the Firebase authentication SDK.

Navigate to home page after successful Registration

///add this firebase packages to pubspec.yaml
firebase_core: ^1.4.0
firebase_auth: ^3.0.0

Retrieve user input text from a widget and call the register function. To retrieve information from the text field, I used the onChanged method.

registration page
jemosop account has been created

If you get a firebase error refer to this tutorial on firebase.

Login

To login/sign-in into a new account, we will use signInWithEmailAndPassword() method. This works the same way as the registration function but the method will be different.

login function.

Navigate to home page after successful Login

N.B you don’t have to rewrite the refactored code below the class widget. You can import the one we created in the registration class.

Function to sign out

void logout() async{
await _auth.signOut();
Navigator.pop(context);
}

Add an icon to your app bar and tap to sign out

appBar: AppBar(
actions: <Widget>[
IconButton(
icon: Icon(Icons.close),
onPressed: () {
// _auth.signOut();
// Navigator.pop(context);
logout();
// getMessages();
//Implement logout functionality
}),
],
backgroundColor: Colors.lightBlueAccent,
),

If you encounter a problem, check if your classes are stateful widget.

You will be able to register and login successfully.

Keep user signed in to your application when application restarts

add data into cloud firestore

HAPPY CODING!!!!!!!!!!!!!!!!!!!!!!!!!!!!

--

--

Mercy Jemosop

Software Developer. I am open to job referrals. connect with me on twitter @kipyegon_mercy