firebase_auth 0.4.5

  • Example
  • Installing
  • Versions
  • 95

firebase_auth plugin

A Flutter plugin to use the Firebase Authentication API.

pub package

For Flutter plugins for other Firebase products, see

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!


Configure the Google sign-in plugin

The Google Sign-in plugin is required to use the firebase_auth plugin. Follow the Google sign-in plugin installation instructions.

Import the firebase_auth plugin

To use the firebase_auth plugin, follow the plugin installation instructions.

Android integration

Enable the Google services by configuring the Gradle scripts as such.

  1. Add the classpath to the [project]/android/build.gradle file.
dependencies {
  // Example existing classpath
  classpath ''
  // Add the google services classpath
  classpath ''
  1. Add the apply plugin to the [project]/android/app/build.gradle file.
apply plugin: ''

Note: If this section is not completed you will get an error like this:

Default FirebaseApp is not initialized in this process [package name].
Make sure to call FirebaseApp.initializeApp(Context) first.

Note: When you are debugging on android, use a device or AVD with Google Play services. Otherwise you will not be able to authenticate.

Use the plugin

Add the following imports to your Dart code:

import 'package:firebase_auth/firebase_auth.dart';

Initialize FirebaseAuth:

final FirebaseAuth _auth = FirebaseAuth.instance;

You can now use the Firebase _auth to authenticate in your Dart code, e.g.

Future<FirebaseUser> _handleSignIn() async {
  GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  GoogleSignInAuthentication googleAuth = await googleUser.authentication;
  FirebaseUser user = await _auth.signInWithGoogle(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  print("signed in " + user.displayName);
  return user;

Then from the sign in button onPress, call the _handleSignIn method using a future callback for both the FirebaseUser and possible exception.

    .then((FirebaseUser user) => print(user))
    .catchError((e) => print(e));


See the example application source for a complete sample app using the Firebase authentication.

Issues and feedback

Please file issues to send feedback or report a bug. Thank you!


  • Enabled use in Swift projects.


  • Added support for sendPasswordResetEmail


  • Moved to the io.flutter.plugins organization.


  • Added support for changing user data


  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.


  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.
  • Relaxed GMS dependency to [11.4.0,12.0[


  • Added FLT prefix to iOS types
  • Change GMS dependency to 11.4.+


  • Change GMS dependency to 11.+


  • Breaking Change: Method FirebaseUser getToken was renamed to getIdToken.


  • Added support for linkWithCredential with Google credential


  • Added support for signInWithCustomToken
  • Added Stream<FirebaseUser> onAuthStateChanged event to listen when the user change


  • Aligned author name with rest of repo.


  • Remove dependency on Google/SignIn


  • Remove dependency on FirebaseUI


  • Added support for linkWithEmailAndPassword


  • Breaking Change: Method currentUser is async now.


  • Added support for signInWithFacebook


  • Updated to Firebase SDK to always use latest patch version for 11.0.x builds


  • Updated to Firebase SDK Version 11.0.1
  • Breaking Change: You need to add a maven section with the "" endpoint to the repository section of your android/build.gradle. For example:
allprojects {
    repositories {
        maven {                              // NEW
            url ""   // NEW
        }                                    // NEW


  • Add method getToken() to FirebaseUser


  • Updated


  • Added support for createUserWithEmailAndPassword, signInWithEmailAndPassword, and signOut Firebase methods


  • Updated


  • Bump buildToolsVersion to 25.0.3


  • Initial Release


// 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 'dart:async';
import 'dart:io';

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

final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = new GoogleSignIn();

void main() {
  runApp(new MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Firebase Auth Demo',
      home: new MyHomePage(title: 'Firebase Auth Demo'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  _MyHomePageState createState() => new _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  Future<String> _message = new Future<String>.value('');

  Future<String> _testSignInAnonymously() async {
    final FirebaseUser user = await _auth.signInAnonymously();
    assert(user != null);
    assert(await user.getIdToken() != null);
    if (Platform.isIOS) {
      // Anonymous auth doesn't show up as a provider on iOS
    } else if (Platform.isAndroid) {
      // Anonymous auth does show up as a provider on Android
      assert(user.providerData.length == 1);
      assert(user.providerData[0].providerId == 'firebase');
      assert(user.providerData[0].uid != null);
      assert(user.providerData[0].displayName == null);
      assert(user.providerData[0].photoUrl == null);
      assert(user.providerData[0].email == null);

    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);

    return 'signInAnonymously succeeded: $user';

  Future<String> _testSignInWithGoogle() async {
    final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
    final GoogleSignInAuthentication googleAuth =
        await googleUser.authentication;
    final FirebaseUser user = await _auth.signInWithGoogle(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    assert( != null);
    assert(user.displayName != null);
    assert(await user.getIdToken() != null);

    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);

    return 'signInWithGoogle succeeded: $user';

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      body: new Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          new MaterialButton(
              child: const Text('Test signInAnonymously'),
              onPressed: () {
                setState(() {
                  _message = _testSignInAnonymously();
          new MaterialButton(
              child: const Text('Test signInWithGoogle'),
              onPressed: () {
                setState(() {
                  _message = _testSignInWithGoogle();
          new FutureBuilder<String>(
              future: _message,
              builder: (_, AsyncSnapshot<String> snapshot) {
                return new Text( ?? '',
                    style: const TextStyle(
                        color: const Color.fromARGB(255, 0, 155, 0)));

1. Depend on it

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

  firebase_auth: "^0.4.5"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:

import 'package:firebase_auth/firebase_auth.dart';
Version Uploaded Documentation Archive
0.4.5 Feb 15, 2018 Go to the documentation of firebase_auth 0.4.5 Download firebase_auth 0.4.5 archive
0.4.4 Feb 5, 2018 Go to the documentation of firebase_auth 0.4.4 Download firebase_auth 0.4.4 archive
0.4.3 Jan 18, 2018 Go to the documentation of firebase_auth 0.4.3 Download firebase_auth 0.4.3 archive
0.4.2 Jan 13, 2018 Go to the documentation of firebase_auth 0.4.2 Download firebase_auth 0.4.2 archive
0.4.1 Jan 12, 2018 Go to the documentation of firebase_auth 0.4.1 Download firebase_auth 0.4.1 archive
0.4.0 Dec 20, 2017 Go to the documentation of firebase_auth 0.4.0 Download firebase_auth 0.4.0 archive
0.3.2 Dec 14, 2017 Go to the documentation of firebase_auth 0.3.2 Download firebase_auth 0.3.2 archive
0.3.1 Oct 17, 2017 Go to the documentation of firebase_auth 0.3.1 Download firebase_auth 0.3.1 archive
0.3.0 Oct 17, 2017 Go to the documentation of firebase_auth 0.3.0 Download firebase_auth 0.3.0 archive
0.2.5 Oct 11, 2017 Go to the documentation of firebase_auth 0.2.5 Download firebase_auth 0.2.5 archive

All 23 versions...


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 15, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1
  • Flutter: 0.0.22


Describes how popular the package is relative to other packages. [more]
99 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
76 / 100
Overall score:
Weighted score of the above. [more]


Detected platforms: unsure

Error(s) prevent platform classification.


  • Fix dependencies in pubspec.yaml.

    Running flutter packages pub upgrade failed with the following output:

    ERR: Invalid argument(s): Minimum version ("2.0.0-dev.23.0") must be less than maximum ("2.0.0-dev.16.0").
    ERR: package:pub_semver/src/version_range.dart 59         new VersionRange
     package:pub/src/pubspec.dart 366                     Pubspec._ensureEnvironment
     package:pub/src/pubspec.dart 331                     Pubspec.dartSdkConstraint
     package:pub/src/solver/backtracking_solver.dart 511  BacktrackingSolver._checkPubspecMatchesSdkConstraint
     package:pub/src/solver/backtracking_solver.dart 474  BacktrackingSolver._checkVersion
     ===== asynchronous gap ===========================
     package:pub/src/solver/backtracking_solver.dart 432  BacktrackingSolver._findValidVersion.<fn>
     ===== asynchronous gap ===========================
     dart:async                                           Future.doWhile
     package:pub/src/solver/backtracking_solver.dart 430  BacktrackingSolver._findValidVersion
     package:pub/src/solver/backtracking_solver.dart 337  BacktrackingSolver._versionQueueFor
     ===== asynchronous gap ===========================
     package:pub/src/solver/backtracking_solver.dart 290  BacktrackingSolver._solve.<fn>
     ===== asynchronous gap ===========================
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/backtracking_solver.dart 315  BacktrackingSolver._solve.<fn>
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 64
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 91     VersionSelection._addDependencies
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 91     VersionSelection._addDependencies
    ERR: This is an unexpected error. Please run
         pub --trace upgrade --verbosity io --no-precompile
     and include the logs in an issue on
  • Fix platform conflicts.

    Make sure none of the libraries use mutually exclusive dependendencies.

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0