• This repository has been archived on 07/Sep/2022
  • Stars
    star
    409
  • Rank 104,889 (Top 3 %)
  • Language
    Dart
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dart wrapper for Firebase

Pub Package

This package is discontinued and will receive no further updates

Feel free to fork the repository and use/extend the code for your needs.

PLEASE NOTE: If you're looking for a package to use in your Flutter app, please have a look at the official documentation: firebase.google.com/docs/flutter.

Introduction

NOTE: This package provides three libraries:

Other platforms

Firebase Configuration

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, storage and/or firestore in the Firebase console.

If you want to use Firestore, you need to enable it in the Firebase console and include the additional js script.

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

Using this package for browser applications

You must include the right Firebase JavaScript libraries into your .html file to be able to use this package. Usually this means including firebase-app.js as well as one or more libraries corresponding to the features you are using.

For example:

<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-firestore.js"></script>

The firestore library is available in firestore.dart. You can find an example how to use this library in the example/firestore.

Real-time Database Example

import 'package:firebase/firebase.dart';

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

  Database db = database();
  DatabaseReference ref = db.ref('messages');

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

Firestore Example

import 'package:firebase/firebase.dart';
import 'package:firebase/firestore.dart' as fs;

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

  fs.Firestore store = firestore();
  fs.CollectionReference ref = store.collection('messages');

  ref.onSnapshot.listen((querySnapshot) {
    querySnapshot.docChanges().forEach((change) {
      if (change.type == "added") {
        // Do something with change.doc
      }
    });
  });
}

Using this package with the Dart VM and Fuchsia

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, storage and firestore 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/Realtime 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.

Firestore tests and example

To be able to run tests and example, Firestore needs to be enabled in the Database/Cloud Firestore section.

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

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

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

You also need to include the additional firebase-firestore.js script. See more info.

Storage tests and example

Storage tests and example need to have public rules to be able to read and write to storage. Firebase Storage Rules Version 2 is required for list and listAll. Update your rules in Firebase console, Storage/Rules section to:

rules_version = '2';
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.

Remote Config example

In order to use Remote Config functionality in your web app, you need to include the following script in your .html file, in addition to the other Firebase scripts:

<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-remote-config.js"></script>

Remote config parameters are defined in Firebase console. Three data types are supported by the API: String, Number, and Boolean. All values are stored by Firebase as strings. It's your responsibility to assure that numbers and booleans are defined appropriately. A boolean value can be represented as either of: 0/1, true/false, t/f, yes/no, y/n, on/off.

For example:

title: Welcome
counter: 2
flag: true

Below is a simple example of consuming remote config:

final rc = firebase.remoteConfig();
await rc.ensureInitialized();
rc.defaultConfig = {'title': 'Hello', 'counter': 1, 'flag': false};
print('title: ${rc.getString("title")}');             // <-- Hello
print('counter: ${rc.getNumber("counter").toInt()}'); // <-- 1
print('flag: ${rc.getBoolean("flag")}');              // <-- false
await rc.fetchAndActivate();
print('title: ${rc.getString("title")}');             // <-- Welcome
print('counter: ${rc.getNumber("counter").toInt()}'); // <-- 2
print('flag: ${rc.getBoolean("flag")}');              // <-- true

Refer to Remote Config Documentation for more details.

Remote Config tests

In order to test remote config, you need to obtain service account credentials for your Firebase project. Each Firebase project has a default service account that will work for this purpose. The service account can be found in the GCP console by choosing the project, then in the menu: IAM & admin > Service accounts.

Once you have located the service account, choose Actions > Create key. Pick JSON as the format. Put the JSON file in lib/src/assets/service_account.json.

Ensure that the remote config for your project is empty. The unit test will refuse to run with the following message if it detects that the remote config of the project is not empty on start:

This unit test requires remote config to be empty.

This is done to avoid overwriting your remote config in case if you run the test in a Firebase project that is used for other purposes.

More Repositories

1

code-prettify

An embeddable script that makes source-code snippets in HTML prettier.
JavaScript
5,768
star
2

chromedeveditor

Chrome Dev Editor is a developer tool for building apps on the Chrome platform - Chrome Apps and Web Apps, in JavaScript or Dart. (NO LONGER IN ACTIVE DEVELOPMENT)
Dart
2,924
star
3

android-Camera2Basic

Migrated:
Java
2,863
star
4

android-ConstraintLayoutExamples

Migrated:
Java
2,571
star
5

firebase-jobdispatcher-android

DEPRECATED please see the README.md below for details.
Java
1,796
star
6

vrview

Library for embedding immersive media into traditional websites.
JavaScript
1,709
star
7

tiger

Java
1,645
star
8

flipjs

A helper library for doing FLIP animations.
JavaScript
1,409
star
9

android-PictureInPicture

Migrated:
Java
1,393
star
10

android-FingerprintDialog

Migrated:
Java
1,375
star
11

observe-js

A library for observing Arrays, Objects and PathValues
JavaScript
1,357
star
12

PyDrive

Google Drive API Python wrapper library
Python
1,304
star
13

js-marker-clusterer

A marker clustering library for the Google Maps JavaScript API v3.
JavaScript
1,279
star
14

android-RuntimePermissions

This sample has been deprecated/archived. Check this repo for related samples:
Java
1,263
star
15

android-Camera2Video

Migrated:
Java
1,201
star
16

chromium-webview-samples

Useful examples for Developing apps with the Chromium based WebView
Java
1,173
star
17

androidtv-Leanback

Migrated:
Java
1,148
star
18

caja

Caja is a tool for safely embedding third party HTML, CSS and JavaScript in your website.
Java
1,126
star
19

android-ui-toolkit-demos

Migrated:
Java
1,118
star
20

android-ScreenCapture

Migrated:
Java
1,021
star
21

android-BluetoothChat

Migrated:
Java
986
star
22

android-BluetoothLeGatt

Migrated:
Java
911
star
23

sample-media-pwa

A sample video-on-demand media Progressive Web App
JavaScript
889
star
24

ChromeWebLab

The Chrome Web Lab for Makers, Hackers and everyone
JavaScript
877
star
25

big-rig

A proof-of-concept Performance Dashboard, CLI and Node module
CSS
857
star
26

android-instant-apps

Migrated:
Java
847
star
27

cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
JavaScript
827
star
28

guitar-tuner

A web-based guitar tuner
JavaScript
822
star
29

android-JobScheduler

This sample has been deprecated/archived. Check this repo for related samples:
Java
773
star
30

flashlight

A pluggable integration with ElasticSearch to provide advanced content searches in Firebase.
JavaScript
757
star
31

friendlypix

FriendlyPix is a cross-platform Firebase example app
726
star
32

voice-memos

A Progressive Web App for recording and playing back voice memos.
JavaScript
724
star
33

android-audio-high-performance

We now recommend you use the Oboe libraries:
C++
715
star
34

android-EmojiCompat

Migrated:
Java
707
star
35

android-RecyclerView

Migrated:
Java
675
star
36

ios-swift-chat-example

FireChat implemented in Swift!
Objective-C
673
star
37

leanback-showcase

Migrated:
Java
639
star
38

android-transition-examples

Migrated:
581
star
39

geofire

Realtime location queries with Firebase
569
star
40

drive-music-player

Fully client side Music Player for Google Drive
JavaScript
566
star
41

android-viewpager2

Migrated:
552
star
42

science-journal-ios

Use the sensors in your mobile devices to perform science experiments. Science doesn’t just happen in the classroom or labβ€”tools like Science Journal let you see how the world works with just your phone.
Swift
532
star
43

topeka

quiz app
HTML
532
star
44

android-PdfRendererBasic

Migrated:
Java
522
star
45

science-journal

Use the sensors in your mobile devices to perform science experiments. Science doesn’t just happen in the classroom or labβ€”tools like Science Journal let you see how the world works with just your phone.
Java
508
star
46

tango-examples-java

Example projects for Project Tango [deprecated] Java API
Java
500
star
47

AndroidChat

Demonstrates using the Firebase Android SDK to back a ListView.
Java
499
star
48

android-nearby

Migrated:
Java
494
star
49

android-play-places

Deprecated:
Java
479
star
50

tango-examples-unity

Project Tango [deprecated] UnitySDK Example Projects
C#
475
star
51

easygoogle

Simple wrapper library for Google APIs
Java
471
star
52

firefeed

JavaScript
461
star
53

android-dynamic-features

Migrated:
Kotlin
460
star
54

android-MediaBrowserService

This sample is deprecated.
Java
457
star
55

graphd

The Metaweb graph repository server
C
445
star
56

drive-zipextractor

Extract (decompress) ZIP files into Google Drive using the Google Drive API
JavaScript
435
star
57

android-AutofillFramework

Migrated:
Java
432
star
58

webplatform-samples

HTML5 Samples/Demos
430
star
59

cloud-functions-go

Unofficial Native Go Runtime for Google Cloud Functions
Go
427
star
60

android-unsplash

Deprecated:
424
star
61

android-MultiWindowPlayground

Migrated:
Java
418
star
62

appengine-flask-skeleton

A skeleton for creating Python applications using the Flask framework on App Engine
Python
416
star
63

angularfire-seed

Seed project for AngularFire apps
JavaScript
412
star
64

node-big-rig

A CLI version of Big Rig
JavaScript
410
star
65

android-Camera2Raw

Migrated:
Java
386
star
66

js-store-locator

A library for easily building store-locator-type applications using the Google Maps JavaScript API v3
JavaScript
380
star
67

ADBPlugin

Google Chrome Extension with ADB Daemon
C++
372
star
68

android-fit

Migrated:
Java
372
star
69

android-NotificationChannels

This sample has been deprecated/archived. Check this repo for related samples:
Java
369
star
70

appengine-php-wordpress-starter-project

Starter project for running WordPress on Google Cloud Platform
PHP
368
star
71

android-ActivitySceneTransitionBasic

Migrated:
368
star
72

android-text

Migrated:
Kotlin
363
star
73

android-XYZTouristAttractions

Migrated:
356
star
74

firebase-angular-starter-pack

A Firebase + AngularJS Starter Pack
JavaScript
348
star
75

android-OurStreets

Migrated:
345
star
76

tango-examples-c

JNI example projects for Project Tango [deprecated] C-API
C++
334
star
77

simian

Simian is an enterprise-class Mac OS X software deployment solution. Google App Engine hosted server, with a client powered by the Munki open-source project.
Python
334
star
78

OpenInChrome

Open in Chrome
Objective-C
333
star
79

android-DownloadableFonts

Migrated:
Java
319
star
80

friendlypix-web

FriendlyPix is a cross-platform Firebase example app - This is the web version
JavaScript
312
star
81

pywebsocket

WebSocket server and extension for Apache HTTP Server for testing
Python
310
star
82

android-DarkTheme

migrated:
Java
302
star
83

firereader

Firereader: A feed reader built with Firebase and AngularJS
JavaScript
301
star
84

android-WatchFace

Migrated:
300
star
85

android-MediaRecorder

Migrated:
Java
299
star
86

backbonefire

Backbone bindings for Firebase
JavaScript
291
star
87

TemplateBinding

TemplateBinding Prolyfill
JavaScript
291
star
88

firebase-login-demo-android

Java
280
star
89

Firebase-Unity

Objective-C
279
star
90

seed-element

Polymer element boilerplate
HTML
278
star
91

firebase-util

An experimental toolset for Firebase
JavaScript
276
star
92

android-NavigationDrawer

This sample has been deprecated/archived. Check this repo for related samples:
Java
276
star
93

android-DisplayingBitmaps

Migrated:
Java
272
star
94

wReader-app

RSS Reader written using AngularJS
JavaScript
271
star
95

gcm-playground

CSS
268
star
96

android-CardView

Migrated:
Java
265
star
97

soundstagevr

C#
263
star
98

ShadowDOM

ShadowDOM Polyfill
JavaScript
263
star
99

android-credentials

Migrated:
Java
260
star
100

gamebuilder

Game Builder is an application that allows users to create games with little or no coding experience.
C#
253
star