Source code for login demo in Coding with Flutter series

Overview

Flutter & Firebase Authentication demo

Source code based on my Flutter & Firebase Authentication video series:

Preview

Firebase configuration

You need to register the project with your own Firebase account.

  • Use com.flutter.logindemo as your bundle / application ID when generating the Firebase project.

  • Download the ios/Runner/GoogleService-Info.plist and android/app/google-services.json files as needed.

License: MIT

Comments
  • Userid

    Userid

    Hi how can I get user ID with AouthProvider.of(context).aouth.surentUser();

    I want to get user ID as setting in different page

    Thank you love your work

    opened by maah75 3
  • Casting issue

    Casting issue

    compiler message: lib/root_page.dart:57:24: Error: A value of type '#lib1::BaseAuth' can't be assigned to a variable of type '#lib2::BaseAuth'. compiler message: Try changing the type of the left hand side, or casting the right hand side to '#lib2::BaseAuth'. compiler message: auth: widget.auth, compiler message: ^ Compiler failed on C:\Users\Dell-pc\AndroidStudioProjects\login_app\lib\main.dart

    FAILURE: Build failed with an exception.

    opened by RishabhMaheshwari 3
  • Auth can't be assigned to a variable type of BaseAuth

    Auth can't be assigned to a variable type of BaseAuth

    I believe I have implemented your code and have even gone as far as to copy and paste but I get the following error:

    compiler message: lib/main.dart:14:13: Error: A value of type '#lib1::Auth' can't be assigned to a variable of type '#lib2::BaseAuth'.
    compiler message: Try changing the type of the left hand side, or casting the right hand side to '#lib2::BaseAuth'.
    compiler message:       auth: Auth(),
    compiler message:             ^
    

    google_sign_in: 3.0.4 firebase_auth: 0.5.18

    opened by puravsanghani 1
  • Flutter firebase_auth errors

    Flutter firebase_auth errors

    I'm fumbling with my loginPage.dart. I upgraded the pre- 1.12 project. This seems to be the last part of the migration

    I made the errors bold within the code block

    The Errors are: ‘User’ isn’t a function Try correcting the name to match an existing function, or define a method or function named ‘User’

    Error: The getter ‘did’, isn’t defined for the type ‘UserCredential’ Try importing the library that defines ‘did’, correcting the name from all but one of the imports

    Error: User’ isn’t a function Try correcting the name to match an existing function, or define a method or function named ‘User’

    Hopefully some one can help me out?

    Looking forward hearing from you! Kind regards, Robert

    From firebase_core: ^0.4.0+1 to firebase_core: ^0.5.0 From firebase_auth: ^0.11.1+3 to firebase_auth: ^0.18.0+1 From cloud_firestore: ^0.12.7+1 to cloud_firestore: ^0.14.0+2 From firebase_storage: ^3.0.4 to firebase_storage: ^4.0.0

     import 'package:flutter/material.dart';
    import 'package:firebase_auth/firebase_auth.dart';
    
    import '../Models/appConstants.dart';
    import '../Models/userObjects.dart';
    import './guestHomePage.dart';
    import './signUpPage.dart';
    
    class LoginPage extends StatefulWidget {
      static final String routeName = '/loginPageRoute';
    
      LoginPage({Key key}) : super(key: key);
    
      @override
      _LoginPageState createState() => _LoginPageState();
    }
    
    class _LoginPageState extends State<LoginPage> {
      final _formKey = GlobalKey<FormState>();
      TextEditingController _emailController = TextEditingController();
      TextEditingController _passwordController = TextEditingController();
    
      void _signUp() {
        if (_formKey.currentState.validate()) {
          String email = _emailController.text;
          String password = _passwordController.text;
          **AppConstants.currentUser = User();**
          AppConstants.currentUser.email = email;
          AppConstants.currentUser.password = password;
          Navigator.pushNamed(context, SignUpPage.routeName);
        }
      }
    
      void _login() {
        if (_formKey.currentState.validate()) {
          String email = _emailController.text;
          String password = _passwordController.text;
          FirebaseAuth.instance
              .signInWithEmailAndPassword(
            email: email,
            password: password,
          )
              .then((firebaseUser) {
            **String userID = firebaseUser.uid;**
            **AppConstants.currentUser = User(id: userID);**
            AppConstants.currentUser
                .getPersonalInfoFromFirestore()
                .whenComplete(() {
              Navigator.pushNamed(context, GuestHomePage.routeName);
            });
          });
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: SingleChildScrollView(
            child: Center(
              child: Padding(
                padding: const EdgeInsets.fromLTRB(50, 100, 50, 0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      'Welcome to ${AppConstants.appName}!',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 30.0,
                      ),
                      textAlign: TextAlign.center,
                    ),
                    Form(
                      key: _formKey,
                      child: Column(
                        children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.only(top: 35.0),
                            child: TextFormField(
                              decoration: InputDecoration(labelText: 'Email'),
                              style: TextStyle(
                                fontSize: 25.0,
                              ),
                              validator: (text) {
                                if (!text.contains('@')) {
                                  return 'Please enter a valid email';
                                }
                                return null;
                              },
                              controller: _emailController,
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(top: 25.0),
                            child: TextFormField(
                              decoration: InputDecoration(labelText: 'Password'),
                              style: TextStyle(
                                fontSize: 25.0,
                              ),
                              obscureText: true,
                              validator: (text) {
                                if (text.length < 6) {
                                  return 'Password must be at least 6 characters';
                                }
                                return null;
                              },
                              controller: _passwordController,
                            ),
                          )
                        ],
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(top: 30.0),
                      child: MaterialButton(
                        onPressed: () {
                          _login();
                        },
                        child: Text(
                          'Login',
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 25.0,
                          ),
                        ),
                        color: Colors.blue,
                        height: MediaQuery.of(context).size.height / 12,
                        minWidth: double.infinity,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10),
                        ),
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(top: 30.0),
                      child: MaterialButton(
                        onPressed: () {
                          _signUp();
                        },
                        child: Text(
                          'Sign Up',
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 25.0,
                          ),
                        ),
                        color: Colors.grey,
                        height: MediaQuery.of(context).size.height / 12,
                        minWidth: double.infinity,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        );
      }
    }
    
    
    opened by Robert126 0
  • Inherited widget

    Inherited widget

    • [x] Add AuthProvider as an implementation of InheritedWidget
    • [x] Use it to get access to auth in RootPage, LoginPage, HomePage
    • [x] Remove auth injection in RootPage, LoginPage, HomePage
    opened by bizz84 0
  • auth.dart and login.dart error

    auth.dart and login.dart error

    when i cloned the project and run so error comes in auth.dart and in login page . how can i fix this.

    error in auth.dart is "A value of type 'AuthResult' can't be assigned to a variable of type 'FirebaseUser'. code is given below

    class Auth implements BaseAuth { final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

    Future signIn(String email, String password) async { FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password); return user.uid; } Future createUser(String email, String password) async { FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password); return user.uid; }

    and error in login The method 'signInWithEmailAndPassword' isn't defined for the class 'BaseAuth'. code is given below

    Future validateAndSubmit() async { if (validateAndSave()) { try { final BaseAuth auth = AuthProvider.of(context).auth; if (_formType == FormType.login) { final String userId = await auth.signInWithEmailAndPassword(_email, _password); print('Signed in: $userId'); } else { final String userId = await auth.createUserWithEmailAndPassword(_email, _password); print('Registered user: $userId'); } widget.onSignedIn(); } catch (e) { print('Error: $e'); } } }

    opened by vinayraj010 0
  • When upgrading to latest Auth

    When upgrading to latest Auth

    Greetings,

    The latest auth package is 0.14.0+5.

    This is required as some of the newer packages like storage is 3.0.6 requires a newer auth.

    When you upgrade to that version of the auth package, the lines no longer work.

    
     Future<String> signInWithEmailAndPassword(String email, String password) async {
        final FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
     
        return user?.uid;
      }
    
    

    The _firebaseAuth.signIn... now returns a different type, of AuthResult.

    So I changed the code to be, (as a guess)

    
     Future<String> signInWithEmailAndPassword(String email, String password) async {
        final AuthResult auth = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
        final FirebaseUser user = auth.user; 
        return user?.uid;
      }
    
    
    

    My new update actually doesn't log on and gets an error of casting from Null.

    Any ideas?

    opened by jamiethain 0
  • Logout from any page

    Logout from any page

    This is not so much an issue, but more a question about the YouTube video that you posted on March 7, 2019 (i.e. Flutter & Firebase authentication with streams and StreamBuilder)

    After completing the steps in the video, we can only logout from the HomePage! From the HomePage, if we Push or PushReplacement a new route, and try to logout from that new route, we are not redirected to the LoginPage.

    How would you change your code to be able to logout from any page? I'm sure many people are wondering the same thing :)

    Thanks a lot!

    opened by fpb-bliinx 3
  •  sign in error

    sign in error

    Hi Thank you for the lesson its really helpful. i keep getting this issue when i try to login.

    Notifying auth state listeners. D/FirebaseApp(21644): Notified 0 auth state listeners. I/flutter (21644): Signed in: 5LL4lM0lOVScxfF5oSmTHmvxotW2 I/flutter (21644): Error: NoSuchMethodError: The method 'call' was called on null. I/flutter (21644): Receiver: null I/flutter (21644): Tried calling: call()

    the authentication works fine as you can see it returns uid. but it doesnt re direct to the new page i created

    opened by Gkusekwa 0
  • App crashing on launch

    App crashing on launch

    I've been trying to fix it but every time it fails to launch on the device. Initializing gradle, Resolving Dependencies, Gradle build all works properly. It even get's installed but it does not launch. It just crashes. FYI I am using Android 7 Nougat in a Xiomi Redmi Note 4. Please check if it is a device specific issue, or is it doing so in your's too.

    opened by rshrc 2
Releases(update-gradle-and-flutter-1.2)
Owner
Andrea Bizzotto
Flutter GDE ❖ Creator of codewithandrea.com ❖ YouTube: nnbd.me/yt ❖ Complete Dart Course: nnbd.me/dart
Andrea Bizzotto
A Flutter mobile application built completely using DhiWise and Supabase without coding single line of code. With 100% system generated code

Flutter Expension Getting Started with Flutter ?? Generated with ❤️ from Dhiwise A Flutter mobile application built completely using DhiWise and Supab

DhiWise 11 Oct 23, 2022
It's OK to love Flutter and hate hand-coding design elements. Parabeac-Core converts design files into Flutter code.

Parabeac-Core Parabeac-Core converts design files into Flutter code driven by open-source & community. Contribute · Discord Community · Designer Proto

Parabeac 536 Jan 4, 2023
Open source Flutter package, bar indicator made of a series of selected and unselected steps

Step Progress Indicator Open source Flutter package, bar indicator made of a series of selected and unselected steps. Made by Sandro Maglione, check o

Sandro Maglione 138 Dec 15, 2022
A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

PengHui Li 112 Nov 11, 2022
Web3-demo-flutter - A demo for the flutter web3 library.

web3_demo_flutter A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you starte

Tommaso Azzalin 0 Oct 7, 2022
"Login Demo" app which shows how to use google sign in Android and iOS using Flutter.

⚠️ ARCHIVED: This repository is using Flutter 1.7 for the sample app. You can find the latest version of the similar implementation on this new repo.

Souvik Biswas 195 Dec 2, 2022
Flutter + Firebase Auth Demo App that uses Google, Facebook, Email/Password Signup/Login, Email Verification and more!

Flutter Firebase Auth Demo Flutter + Firebase Auth Demo App that uses Google, Facebook, Email/Password Signup/Login, Email Verification and more! Feat

Rivaan Ranawat 55 Jan 7, 2023
Flutter talk - Repository with a live coding from a talk about Flutter

Don't do drugs, do Flutter! Repository with a live coding from a talk about Flutter.

null 12 Dec 17, 2022
Flutter form fields designed to take much of the burden of form-related coding off the programmer's back — masks, validations, keyboard type, etc.

well_formed Contents Overview Getting Started Demo application References Overview Well-Formed Widget Fields - Well-Formed - is a collection of Flutte

Dartoos 7 Nov 2, 2022
Tonal : UI Coding Challenge For Flutter

Tonal - UI Coding Challenge Modern UI engineering is all about components. When we build components to be reusable, we enable faster iteration and hig

Max Shemetov 3 Mar 10, 2022
Flutter movie review - Movie Review Clone Coding

movie_review Movie Review Application Clone Coding Getting Started This project is a starting point for a Flutter application. A few resources to get

ParkGil-hyeon 0 Jan 4, 2022
Beautiful Lottery App created in Flutter using Simple coding + State_full Widgets.

lottery_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

null 2 Sep 7, 2022
This is my participation Repo for the 100 days of coding challenge

hundred_days_of_coding Day 1: Started creating Project and using advanced tools to make the development easier Day 2: Added DataClasses with the help

jxstxn__ 3 Nov 21, 2021
Flutter Login Signup - Flutter Login and Signup App

Flutter_Login_Signup Authors @Adiikust License MIT ?? Skills Dart, Flutter, Adob

Adnan Hameed 6 Nov 6, 2022
Flutter Login Screen with Firebase Auth and Facebook Login

Flutter Login Screen with Firebase Auth and Facebook Login Jumpstart your Flutter app development with this pre-built Flutter starter kit. Don't reinv

null 296 Dec 29, 2022
Login-and-reisp - A Mobile app Login Page UI with Flutter

Flutter Login Page UI Watch it on YouTube Mobile app Minimal Auth Screen with Fl

null 10 Sep 8, 2022
Tinder login page - Implementation of the Tinder app login screen with flutter

Tinder (login page) Implementação da tela de login do app Tinder a partir da lei

Eduardo Farias 0 Feb 5, 2022
Flutter Login Screen with Firebase Auth and Facebook Login

Jumpstart your Flutter app development with this pre-built Flutter starter kit. Don't reinvent the wheel by writing the boring boilerplate starter code.

null 12 Dec 19, 2022
Login-page-ui - An animated login page, designed with dart

Beautiful Login Page UI Design and Animation ScreenShots This is one of my best

Munem Sarker 11 Nov 22, 2022