Coder Social home page Coder Social logo

tuzzmaniandevil / flutter_firebase_auth_example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from delay/flutter_firebase_auth_example

0.0 0.0 0.0 388 KB

Flutter firebase authentication email and password example with firestore, local shared preferences and state management.

Java 0.89% Ruby 5.15% Objective-C 1.76% Dart 92.20%

flutter_firebase_auth_example's Introduction

Flutter Auth with Firebase Example

flutter firebase auth screenshots

Currently working on rewriting this code to make use of streams instead... it's a much better way for flutter projects. This code was made for how I thought it should be coming from a js environment, now I know better... I will post here once I have the new project completed.

There are numerous tutorials on using firebase auth with flutter. I went through many of these to work through making my own take on a Firebase Auth flutter project that worked the way I needed it to. Definitely check out these projects which provide much more in depth tutorials.

Simple Recipe app made in flutter firebase and google sign in

Instaflutter

Flutter login UI

How to do user login with firebase

I am still new to flutter so there are probably better ways to handle many of the options in this code. I setup my project to combine firebase auth with saving my user info to shared preferences on the mobile device. When logging in it reads the info from local storage first. If it doesn’t exist, the user logs into firebase and the user and settings data is retrieved from firestore and stored locally. This minimizes the number of requests required from firestore. I wanted to login with an email and password as opposed to logging in with google sign in or facebook sign in.

I also use validation for text fields and handle and display error messages via a snackbar style notification flushbar package. Finally I use global state to keep track of when the data changes.

Overview of files...

main.dart - this file initializes the app and contains the routing as well as the global state setup and references the custom theme.

/ui/

theme.dart - contains some custom theme info.

/ui/screens/

home.dart - HomeScreen when the user is logged in, also redirects the user when he is not logged in to the SignInScreen.

sign_in.dart - SignInScreen . When signing in logs in with Firebase Auth, then retrieves data from the two collections in firestore and saves it locally, also calls the state_widget so the global state can be updated once logged in.

sign_up.dart - SignUpScreen sets up a new user in Firebase Auth and writes two new documents in Firestore, one to the users collection and one to the settings collection on firebase.

forgot_password.dart - ForgotPasswordScreen lets you send a firebase query to reset your password.

/ui/widgets

loading.dart - LoadingScreen - small modification to the excellent package modal_progress_hud to wrap the circular progress indicator.

/util/

auth.dart - The Auth class which controls authenticating and reading and storing info related to auth.

state_widget.dart - The state widget class which initializes the user and logs them in and out.

validator.dart - Validation class with some custom validations for email, password, etc.

/models/

Used quicktype to setup the models but added one extra function for firebase.

settings.dart - model for settings. Eventually this will be used to hold the rest of the app settings.

user.dart - model for user.

state.dart - model for the state.

Anyway hopefully this little project will help someone. Feel free to use any of it, I didn't create all of this code as parts of it came from watching the tutorials and reviewing the projects mentioned above. Make sure you setup firebase with your project.

flutter_firebase_auth_example's People

Contributors

delay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.