firebase_auth_dart 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new48

firebase_auth_dart #

This is a pure Dart implementation for firebase_core intended for use with Flutter. This package uses firebase_core_vm to provide the pure dart implementation which does not and will not support Web apps. While this package will work on Android and iOS, this is not our main focus as for for now, instead we want to bring Firebase to Flutter Desktop.

This package lets you use the firebase_core as you would normally do so you don't need to change you code. If you don't want to use firebase_core you can directly use the firebase_core_vm.

Usage #

1. Add this to your package's dependencies and run flutter pub get:

dependencies:
  firebase_core: ^0.4.4+2
  firebase_auth_dart: ^0.0.1

2. Import it

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth_dart/firebase_auth_dart.dart';

3. Create a Firebase project

If you already have a Firebase project for you mobile/web apps you can skip this step.

4. Initialize the FirebaseApp

 import 'package:firebase_core/firebase_core.dart';
 import 'package:firebase_auth_dart/firebase_auth_dart.dart';
 import 'package:flutter/material.dart';
 
 void main() {
   if (isDesktop) {
     FirebaseAuthDart.register(
       options: const FirebaseOptions(
         apiKey: 'AIzaSyBQgB5s3n8WvyCOxhCws-RVf3C-6VnGg0A',
         projectID: 'flutter-sdk',
         gcmSenderID: '233259864964',
         databaseURL: 'https://flutter-sdk.firebaseio.com',
         storageBucket: 'flutter-sdk.appspot.com',
         clientID:
             '233259864964-go57eg1ones74e03adlqvbtg2av6tivb.apps.googleusercontent.com',
         googleAppID:
             '1:233259864964:macos:0bdc69800dd31cde15627229f39a6379865e8be1',
       ),
     );
   }
   runApp(MyApp());
 }

Note:

  • If you want to use multiple FirebaseApps skip to next section on how to do that.
  • isDesktop is false Web/Mobile context and uses conditional import to achieve that
Create API Key
  1. Go to the Google Cloud Platform console and select you project
  2. Go to APIs & Service -> Credentials
  3. Create new credentials for your app by selecting CREATE CREDENTIALS and then API Key
Create Client ID

If you plan to use Google Sign In, the you need to create a Client ID for you app

  1. Go to the Google Cloud Platform console and select you project
  2. Go to APIs & Service -> Credentials
  3. Create new credentials for your app by selecting CREATE CREDENTIALS and then OAuth client ID
  4. Select Other as Application type, give it a name (eg. macOS) and then click Create
Get configuration from Firebase console
  1. projectID you can be found on the Project Settings tab
  2. gcmSenderID you can be found on the Project Settings -> Cloud Messaging -> Sender ID
  3. databaseURL you can find it on the Database tab and it usually looks like this https://<project-id>.firebaseio.com
  4. storageBucket you can find it on the Storage tab and it usually looks like this <project-id>.appspot.com
Create a applicationId

Since desktop is not an officially supported platform, we need to create applicationId for our local use.

  1. Construct the first part of you applicationId following this pattern <appNumber>:<gcmSenderID>:<os>.
    • googleAppId - TL;DR set it to 1. The appNumber is an incrementing value that starts at 1 and represents the index of your applications for this platform that uses the same Firebase project.
    • gcmSenderID - you can be found on the Project Settings -> Cloud Messaging -> Sender ID
    • os - windows, macos, linux, my-custom-os-because-i-can
  2. Generate the SHA1 hash of this part. You can use this tool
  3. add this value to the first part so you applicationId looks like this <appNumber>:<gcmSenderID>:<platform>:sha1(<appNumber>:<gcmSenderID>:<os>) (eg. 1:233259864964:macos:0bdc69800dd31cde15627229f39a6379865e8be1)

4. Initialize multiple FirebaseApps

  1. make sure you first register this package:
    import 'package:firebase_core/firebase_core.dart';
    import 'package:firebase_auth_dart/firebase_auth_dart.dart';
    import 'package:flutter/material.dart';
    
    void main() {
      if (isDesktop) {
        FirebaseAuthDart.register();
      }
      runApp(MyApp());
    }
    
  2. Use firebase_core to initialize the app you want as you normally would.
      Future<void> _configure() async {
        final FirebaseApp app = await FirebaseApp.configure(
          name: 'foo',
          options: const FirebaseOptions(
            apiKey: 'AIzaSyBQgB5s3n8WvyCOxhCws-RVf3C-6VnGg0A',
            databaseURL: 'https://flutter-sdk.firebaseio.com',
            projectID: 'flutter-sdk',
            storageBucket: 'flutter-sdk.appspot.com',
            gcmSenderID: '233259864964',
            clientID:
                '233259864964-go57eg1ones74e03adlqvbtg2av6tivb.apps.googleusercontent.com',
            googleAppID:
                '1:233259864964:macos:0bdc69800dd31cde15627229f39a6379865e8be1',
          ),
        );
        assert(app != null);
        print('Configured $app');
      }
    

Note: You can have a look at the example app on how you can initialize use different FirebaseOptions depending on the platform you are on.

0.0.1 #

  • Initial release.

example/lib/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:firebase_auth/firebase_auth.dart';
import 'package:firebase_auth_dart/firebase_auth_dart.dart';
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:firebase_core_dart/firebase_core_dart.dart';
import 'package:firebase_core_vm/firebase_core_vm.dart' show isDesktop;
import 'package:flutter/material.dart';
import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';

import './register_page.dart';
import './signin_page.dart';

void main() {
  if (isDesktop) {
    Future.wait(<Future<void>>[
      GoogleSignInDart.register(
        exchangeEndpoint:
            'https://us-central1-flutter-sdk.cloudfunctions.net/authHandler',
        clientId:
            '233259864964-go57eg1ones74e03adlqvbtg2av6tivb.apps.googleusercontent.com',
      ),
      FirebaseCoreDart.register(
        options: const FirebaseOptions(
          apiKey: 'AIzaSyBQgB5s3n8WvyCOxhCws-RVf3C-6VnGg0A',
          databaseURL: 'https://flutter-sdk.firebaseio.com',
          projectID: 'flutter-sdk',
          storageBucket: 'flutter-sdk.appspot.com',
          gcmSenderID: '233259864964',
          googleAppID:
              '1:233259864964:macos:0bdc69800dd31cde15627229f39a6379865e8be1',
        ),
      ),
      FirebaseAuthDart.register(),
    ]);
  }
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Firebase Auth Demo',
      home: MyHomePage(title: 'Firebase Auth Demo'),
    );
  }
}

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

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  FirebaseUser user;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            padding: const EdgeInsets.all(16),
            alignment: Alignment.center,
            child: RaisedButton(
              onPressed: () => _pushPage(context, RegisterPage()),
              child: const Text('Test registration'),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(16),
            alignment: Alignment.center,
            child: RaisedButton(
              onPressed: () => _pushPage(context, SignInPage()),
              child: const Text('Test SignIn/SignOut'),
            ),
          ),
        ],
      ),
    );
  }

  void _pushPage(BuildContext context, Widget page) {
    Navigator.of(context).push(
      MaterialPageRoute<void>(builder: (_) => page),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  firebase_auth_dart: ^0.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:firebase_auth_dart/firebase_auth_dart.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]
89
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Mar 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
built_value ^7.0.9 7.0.9
firebase_auth_platform_interface ^1.1.7 1.1.7
firebase_auth_vm ^0.0.2 0.0.2
firebase_core_vm ^0.0.4 0.0.4
flutter 0.0.0
meta ^1.0.0 1.1.8
url_launcher ^5.4.2 5.4.2
Transitive dependencies
_discoveryapis_commons 0.1.9
_firebase_internal_vm 0.0.2
async 2.4.1
built_collection 4.3.2
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
fixnum 0.10.11
flutter_web_plugins 0.0.0
googleapis 0.54.0
googleapis_auth 0.2.11+1
http 0.12.0+4
http_parser 3.1.4
matcher 0.12.6
path 1.6.4
pedantic 1.9.0
plugin_platform_interface 1.0.2
quiver 2.1.3
rxdart 0.23.1 0.24.0-dev.1
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
url_launcher_macos 0.0.1+4
url_launcher_platform_interface 1.0.6
url_launcher_web 0.1.1+1
vector_math 2.0.8
Dev dependencies
flutter_test