Repository
https://github.com/flutter/flutter
What Will I Learn?
- You will learn how to use add authentication to Firebase/Firestore projects
- You will learn how to use OAuth 2.0 with Firebase/Firestore
- You will learn how to use image filter widgets in flutter
- You will learn how to manage singleton object in a provider class
- You will learn how to use assertions and logic to verify data
Requirements
System Requirements:
- IDEA intellij, Visual Studio Code with the Dart/Flutter Plugins, Android Studio or Xcode
- The Flutter SDK on the latest Master Build
- An Android or iOS Emulator or device for testing
OS Support for Flutter:
- Windows 7 SP1 or later (64-bit)
- macOS (64-bit)
- Linux (64-bit)
Required Knowledge
- A little understanding of key/value stores
- A fair understanding of Mobile development and Imperative or Object Oriented Programming
- Some understanding of realtime databases
Resources for Flutter and this Project:
- Flutter Website: https://flutter.io/
- Flutter Official Documentation: https://flutter.io/docs/
- Flutter Installation Information: https://flutter.io/get-started/install/
- Flutter GitHub repository: https://github.com/flutter/flutter
- Flutter Dart 2 Preview Information: https://github.com/flutter/flutter/wiki/Trying-the-preview-of-Dart-2-in-Flutter
- Flutter Technical Overview: https://flutter.io/technical-overview/
- Dart Website: https://www.dartlang.org/
- Flutter Awesome GitHub Repository: https://github.com/Solido/awesome-flutter
Sources:
Flutter Logo (Google): https://flutter.io/
Difficulty
- Intermediate
Description
Outline and Overview
In this Flutter Video Tutorial, we take a look at how it is possible to authenticate a user using the Google Sign In plugin inside of Firebase and Firestore. The application uses a login page which allows the user to navigate to the home page only if the user is authenticated by Google. Google sends a token to the Firebase console which them verifies that the user is authenticated. If they are authenticated then the user can read and write to our Firestore database. We also make use of the Image Filter Widget in this application to allow us to create a unique aesthetic for our login page. The Singleton pattern is also used and we use assertions in our provider logic.
Outline for this Tutorial
Item 1: Authentication via Google for Firebase/Firestore
There are various reasons why you would want to authenticate a user in a mobile application. With Firebase we are able to not only restrict which users can read and write from our database, we can also use the authentication to identify the users. This allows us to preform analytics as well as save security data in the cloud. We are also able to personalize the application experience with this information to increase application retention.
This image shows the rules that were used for our cloud firestore database in this application. These rules only allow a user to read and write our data if the request they make is authenticated beforehand. This rule set is very simple but it can be expanded in different ways for various types of applications.
Item 2: Using OAuth 2.0 Inside of Flutter
One of the larger advantages of using the Firebase Authentication system is that it makes use of the OAuth 2.0 standard. This allows us to authenticate our users from a single click. We also avoid potential security risks which come from using a more traditional validation system that actually requires that the user inputs their email and password into our application.
This image shows the method that we use to authenticate the user inside of our application. First, we ask Google to authenticate the user by having them sign in to the Google Playstore or another Google application. We then are able to get the Authentication Tokens from this sign in event through our GoogleSignInAuthentication
object. These tokens are passed into the FirebaseUser object which then confirms that the user is indeed who they say they are. The information is then passed back into firebase on a successful authentication.
Item 3: Using the Singleton Pattern to Fetch Consistent Data
Firebase Authentication and the libraries surrounding Firebase all use the Singleton Pattern. This is useful because it allows the application to keep the same instance of the object consistent across the entire code base. In this case, we are able to easily pass the user data from the API provider to the view layer of our application.
Just as we were able to use a Stream Builder widget to dynamically change the widget tree in the base application, we are also able to display information about the user to our home screen. In this case, we are taking the FirebaseAuth
instance object and calling the currentUser
method on it to get the currently signed in user. We are then able to access any piece of information associated with this user in the widget tree below this Stream Builder.
The source code for this project can be found here
The Commands and Firebase Rules used in this tutorial can be found here
Video Tutorial
Related Videos
Projects and Series
Stand Alone Projects:
- Dart Flutter Cross Platform Chat Application Tutorial
- Building a Temperature Conversion Application using Dart's Flutter Framework
- Managing State with Flutter Flux and Building a Crypto Tracker Application with Dart's Flutter Framework
Building a Calculator
- Building a Calculator Layout using Dart's Flutter Framework
- Finishing our Calculator Application with Dart's Flutter Framework
Movie Searcher Application
- Building a Movie Searcher with RxDart and SQLite in Dart's Flutter Framework (Part 1)
- Building a Movie Searcher with RxDart and SQLite in Dart's Flutter Framework (Part 2)
- Building a Movie Searcher with RxDart and SQLite in Dart's Flutter Framework (Part 3, Final)
Minesweeper Game
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 1)
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 2)
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 3)
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 4, Final)
Weather Application
- Building a Weather Application with Dart's Flutter Framework (Part 1, Handling Complex JSON with Built Code Generation)
- Building a Weather Application with Dart's Flutter Framework (Part 2, Creating a Repository and Model)
- Building a Weather Application with Dart's Flutter Framework (Part 3, RxCommand (RxDart) and Adding an Inherited Widget)
- Building a Weather Application with Dart's Flutter Framework (Part 4, Using RxWidget to Build a Reactive User Interface)
- Localize and Internationalize Applications with Intl and the Flutter SDK in Dart's Flutter Framework
Curriculum
- Building a Multi-Page Application with Dart's Flutter Mobile Framework
- Making Http requests and Using Json in Dart's Flutter Framework
- Building Dynamic Lists with Streams in Dart's Flutter Framework
- Using GridView, Tabs, and Steppers in Dart's Flutter Framework
- Using Global Keys to get State and Validate Input in Dart's Flutter Framework
- The Basics of Animation with Dart's Flutter Framework
- Advanced Physics Based Animations in Dart's Flutter Framework
- Building a Drag and Drop Application with Dart's Flutter Framework
- Building a Hero Animation and an Application Drawer in Dart's Flutter Framework
- Using Inherited Widgets and Gesture Detectors in Dart's Flutter Framework
- Using Gradients, Fractional Offsets, Page Views and Other Widgets in Dart's Flutter Framework
- Making use of Shared Preferences, Flex Widgets and Dismissibles with Dart's Flutter framework
- Using the Different Style Widgets and Properties in Dart's Flutter Framework
- Composing Animations and Chaining Animations in Dart's Flutter Framework
- Building a Countdown Timer with a Custom Painter and Animations in Dart's Flutter Framework
- Reading and Writing Data and Files with Path Provider using Dart's Flutter Framework
- Exploring Webviews and the Url Launcher Plugin in Dart's Flutter Framework
- Adding a Real-time Database to a Flutter application with Firebase
- Building a List in Redux with Dart's Flutter Framework
- Managing State with the Scoped Model Pattern in Dart's Flutter Framework
- Authenticating Guest Users for Firebase using Dart's Flutter Framework
- How to Monetize Your Flutter Applications Using Admob
- Using Geolocator to Communicate with the GPS and Build a Map in Dart's Flutter Framework
- Managing the App Life Cycle and the Screen Orientation in Dart's Flutter Framework
- Making use of General Utility Libraries for Dart's Flutter Framework
- Interfacing with Websockets and Streams in Dart's Flutter Framework
- Playing Local, Network and YouTube Videos with the Video Player Plugin in Dart's Flutter Framework
- Building Custom Scroll Physics and Simulations with Dart's Flutter Framework
- Making Dynamic Layouts with Slivers in Dart's Flutter Framework
- Building a Sketch Application by using Custom Painters in Dart's Flutter Framework
- Using Dart Isolates, Dependency Injection and Future Builders in Dart's Flutter Framework
- Looking at the Main Features of the Beta Three Release of Dart's Flutter Framework
- Working with Material Theme and Custom Fonts in Dart's Flutter Framework