auth070 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 46

Auth070 #

In Jan 24, 2019, firebase_auth migrated to AndroidX essentially cutting off the previous Android versions. This package retains those versions if you need to use them. In other words, if you want to not migrate just yet, use this package that will, in turn, continue to use firebase_auth 0.7.0. fireauth080 You may have to consider useing this package if, for example, you encounter the following error: nonnullerror The common solution (in most cases) requires you to 'upgrade' minSdkVersion to at least, 21: minsdk

Auth Class #

This class library works with two plugins: firebase_auth and google_sign_in to log into a Firebase backend using a Firebase account or a Google account. If you're familiar with these plugins, you will find the same functions used in this class library.

How it Works #

Below are a series of screenshots depicting how to initialize and authenticate or 'sign in' an individual in your app's Firebase backend using a either an email and password or a Google account. The following will sign in 'silently' (i.e. automatically if the user had already signed in in the past.). Note, settings are passed as parameters in the screenshot below. 09inistate These examples have the class library called in the State object's iniState() function, but, of course, you could instead 'initialize' the class library in the iniState() function and then 'sign in' elsewhere. Below, the init() function is used instead to initialize the class library.

authinit

There's Setters #

The class library provide an array of setters that you can use instead to first initialize. The 'listen' setter will call the anonymous function when the user either successfully or unsuccessfully logs in. authset

The Last Setter Wins #

By design, the last assignment of a particular setting is the one used by the class library. The the example blow, there is a stretch of code that calls the 'scopes' setting twice. The last instance (in the signInSliently() function) will be the one used. twoscopes Below is a snapshot of the logInWithGoogle() function inside the class library itself. It is this function you will likely use the most. It does the majority of the functionality. It will log in 'silently' if possible, otherwise it will use the user's Google account to log into Firebase. This snapshot gives you an idea of the parameters (options) you have available to you. Again, if you're familiar with the plugins, you'll recognize most of these parameters. loginwithgoogle

signingin

It's All Static #

It's a static class library, and so prefix the word, 'Auth', in front of the function call 'anytime anywhere' in the app, and you're off and running. authcalls

On Medium #

This is a library is covered again in the Medium article, Auth in Flutter. auth

[0.0.1] - Initial github release
[0.0.2] - Format code with dartfmt
[0.0.3] - await _user?.reload();
[0.1.0] - Dec. 10, Change semantic version number to convey development phase.
[0.1.1] - Jan. 17, 2019 await _setFireBaseUserFromGoogle(currentUser);
[1.0.0] - Mar. 07, 2019 Added signInWithCredential, linkWithCredential, fetchSignInMethodsForEmail
Concrete dependencies assigned firebase_auth: "0.7.0" google_sign_in: "3.2.4" #
Breaking Change Removed signInWithFacebook, signInWithTwitter, signInWithGoogle,
Breaking Change linkWithEmailAndPassword, linkWithGoogleCredential, linkWithFacebookCredential

[1.0.1] - Mar. 07, 2019 import 'package:flutter/material.dart';

example/main.dart

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'password.dart';

import 'package:auth070/auth.dart';

void main() {
  runApp(
    MaterialApp(
      title: 'Google Sign In',
      home: SignInDemo(),
    ),
  );
}

class SignInDemo extends StatefulWidget {
  @override
  State createState() => SignInDemoState();
}

class SignInDemoState extends State<SignInDemo> {
  GoogleSignInAccount _currentUser;

  @override
  void initState() {
    super.initState();

    Auth.init(
      listen: (account) {
        setState(() {
          _currentUser = account;
        });
      },
    );

    Auth.signInSilently();
  }

  @override
  void dispose() {
    Auth.dispose();
    super.dispose();
  }

  Widget _buildBody() {
    if (_currentUser != null) {
      return Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          ListTile(
            leading: GoogleUserCircleAvatar(
              identity: _currentUser,
            ),
            title: Text(_currentUser.displayName),
            subtitle: Text(_currentUser.email),
          ),
          const Text("Signed in successfully."),
          RaisedButton(
            child: const Text('SIGN OUT'),
            onPressed: _signOut,
          ),
          RaisedButton(
            child: const Text('SIGN OUT & DISCONNECT'),
            onPressed: _disconnect,
          ),
        ],
      );
    } else {
      return Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          const Text("You are not currently signed in."),
          RaisedButton(
            child: const Text('GOOGLE SIGN IN'),
            onPressed: _signIn,
          ),
          RaisedButton(
            child: const Text('SIGN IN WITH EMAIL & PASSWORD'),
            onPressed: _signInWithEmailAndPassword,
          ),
          RaisedButton(
            child: const Text('SIGN IN ANONYMOUSLY'),
            onPressed: _signInAnonymously,
          ),
        ],
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Authentication Sign In'),
        ),
        body: ConstrainedBox(
          constraints: const BoxConstraints.expand(),
          child: _buildBody(),
        ));
  }

  void _signOut() {
    Auth.signOut();
  }

  void _disconnect() {
    Auth.disconnect();
  }

  void _signIn() {
    Auth.signIn();
  }

  void _signInWithEmailAndPassword() {
    Auth.signInWithEmailAndPassword(
        email: hiddenEmail, password: hiddenPassword);
  }

  void _signInAnonymously() {
    Auth.signInAnonymously();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  auth070: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:auth070/auth.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Oct 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (firebase_auth, google_sign_in).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
firebase_auth 0.7.0 0.7.0 0.14.0+5
flutter 0.0.0
google_sign_in 3.2.4 3.2.4 4.0.7
Transitive dependencies
collection 1.14.11 1.14.12
firebase_core 0.2.5+1 0.4.0+9
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test