Git Product home page Git Product logo

flutter_firebase_auth_benchmark's Introduction

Flutter Firebase Authentication Benchmark

This was an interesting experiment but isn't really going to be scalable or easily turned into a package — everything works though. What I'm going to do is turn it into a package from scratch, focusing on the Flutter native StreamBuilder and rxdart observables and Dart Streams to manage the state of multiple widgets when necessary, instead of using Provider or other high-level packages. This repo will still be up as a learning experience for others.

A benchmark for Authentication through Firebase in Flutter.

Heavily inspired design by the flutter_login package, by Near Huscarl. Even though it is not as pretty or so intensely parameterized, the overall structure of the code is much more simple and accessible — in part, this is due to using AnimatedSwitcher and Visibility widgets to handle animations, instead of customized raw animations.

Firebase

Firebase is enabled, however, for security reasons, I chose to omit the json settings files. They are listed inside the .gitignore file.

More info can be found in the docs/ folder.

Tests

I chose to create a real Firebase server for the tests*. So, instead of mocking the Firebase instance, you will find tests which make real requests, thus, needing to use Flutter Driver.

The test utils.dart file features some very handy functions and classes that I spent a lot of time trying to make work. Some of the notable mentions are:


* Basically because I haven't been able to find a trustworthy package for the mocks, and haven't found the patience to implement one myself either. The closest I have been able to a reliable mock is in the firebase_auth package itself. Check out firebase_auth_test.dart.

Email and Password Validation

Email and Password Validation were both accomplished through the use of regular expressions.

  • Email Validation uses this regex.
  • Password Validation uses this regex. And the error messages appear in this order:
    1. Minimum eight characters
    2. At least one uppercase letter
    3. One lowercase letter
    4. One number
    5. One special character

Problems

Architecture

My architecture sucks and yours is amazing, I know, I know.

But if it ain't broken, don't fix it. So I'm not going to remake everything unless there's huge benefit to it.

One of the biggest problems, besides the one with labelText and Provider, is the fact that most of what's in my validator is basically featured inside firebase_auth's API anyway. Ditching out my validator could really reduce a lot of my code's complexity. But I didn't know that beforehand.

The TextFormField Problem

Unfortunately, the source's TextFormField doesn't allow us to disable the errorText, which, in my case, can mess up the design quite badly, since I chose to present the errors in the labelText. However, there seems to be a more or less easy way of fixing this if we add a parameter to the original TextFormField, which is what I did. You can find out more about it in this SO answer (or in Issue #52634).

The errorText on labelText and Provider's notifyListeners() Problem

Since my architecture has the initial Form changing because of the internal AnimatedSwitcher, I think that the Provider's notifyListeners() and the formKey.currentState.save() could happen concurrently.

I couldn't find a clean solution solution to that, so I "fixed" it by delaying the saving with — inside login_workflow_provider.dart —:

Future<void> save() async =>
    await Future.delayed(Duration(milliseconds: 100), () {
      _formKey.currentState.save();
    });

More info about this problem can be found in Issue #31 or in this StackOverflow question.

flutter_firebase_auth_benchmark's People

Contributors

psygo avatar

Watchers

James Cloos 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.