firebase 4.2.0+1 copy "firebase: ^4.2.0+1" to clipboard
firebase: ^4.2.0+1 copied to clipboard

discontinuedreplaced by: firebase_core
outdatedDart 1 only

Dart libraries for Firebase

Firebase APIs for Dart VM (server), Fuchsia, and Browser #

Build Status

Use Firebase REST APIs for dart:io apps (for example: server-side Dart or Fuchsia), and a Dart wrapper for Firebase's JavaScript API for the browser.

If you are writing Flutter apps for iOS and Android, you should use FlutterFire plugins instead.

You can find more information on how to use Firebase on the Getting started page.

Don't forget to setup correct rules for your realtime database and/or storage in the Firebase console.

Authentication also has to be enabled in the Firebase console. For more info, see the next section in this document.

Installation #

Install the library from pub:

dependencies:
  firebase: '^4.0.0'

Using this package with dart:html #

Include Firebase JavaScript source #

You must include the original Firebase JavaScript source into your .html file to be able to use the library.

<script src="https://www.gstatic.com/firebasejs/4.4.0/firebase.js"></script>

Example #

import 'package:firebase/firebase.dart';

void main() {
  initializeApp(
    apiKey: "YourApiKey",
    authDomain: "YourAuthDomain",
    databaseURL: "YourDatabaseUrl",
    storageBucket: "YourStorageBucket");

  Database database = database();
  DatabaseReference ref = database.ref("messages");

  ref.onValue.listen((e) {
    DataSnapshot datasnapshot = e.snapshot;
    // Do something with datasnapshot
  });
}

Using this package with dart:io #

This library also contains a dart:io client.

Create an instance of FirebaseClient and then use the appropriate method (GET, PUT, POST, DELETE or PATCH). More info in the official documentation.

The dart:io client also supports authentication. See the documentation on how to get auth credentials.

import 'package:firebase/firebase_io.dart';

void main() {
  var credential = ... // Retrieve auth credential
  var fbClient = new FirebaseClient(credential); // FirebaseClient.anonymous() is also available
  
  var path = ... // Full path to your database location with .json appended
  
  // GET
  var response = await fbClient.get(path);
  
  // DELETE
  await fbClient.delete(path);
  
  ...
}

Examples #

You can find more examples on realtime database, auth and storage in the example folder.

Dart Dev Summit 2016 demo app #

Demo app which uses Google login, realtime database and storage.

Before tests and examples are run #

You need to ensure a couple of things before tests and examples in this library are run.

All tests and examples #

Create config.json file (see config.json.sample) in lib/src/assets folder with configuration for your Firebase project.

To run the io tests, you need to provide the service_account.json file. Go to Settings/Project settings/Service accounts tab in your project's Firebase console, select the Firebase Admin SDK and click on the Generate new private key button, which downloads you a file. Rename the file to service_account.json and put it into the lib/src/assets folder.

Warning: Use the contents of

lib/src/assets is only for development and testing this package.

App tests #

No special action needed here.

Auth tests and example #

Auth tests and some examples need to have Auth providers correctly set. The following providers need to be enabled in Firebase console, Auth/Sign-in method section:

  • E-mail/password
  • Anonymous
  • Phone

Database tests and example #

Database tests and example need to have public rules to be able to read and write to database. Update your rules in Firebase console, Database/Rules section to:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

Warning: At the moment, anybody can read and write to your database. You usually don't want to have this in your production apps. You can find more information on how to setup correct database rules in the official

Firebase documentation.

Storage tests and example #

Storage tests and example need to have public rules to be able to read and write to storage. Update your rules in Firebase console, Storage/Rules section to:

service firebase.storage {
  match /b/YOUR_STORAGE_BUCKET_URL/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

Warning: At the moment, anybody can read and write to your storage. You usually don't want to have this in your production apps. You can find more information on how to setup correct storage rules in the official

Firebase documentation.

Bugs #

If you find a bug, please file an issue.

260
likes
0
pub points
96%
popularity

Publisher

unverified uploader

Dart libraries for Firebase

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

browser, func, http, js

More

Packages that depend on firebase