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, 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.
Install the library from pub:
dependencies:
firebase: '^4.3.0'
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.10.1/firebase.js"></script>
Include the firebase-firestore.js
script also:
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.10.1/firebase-firestore.js"></script>
Firestore library is available in the firestore.dart
and you can find an example
how to use this library in the example/firestore.
import 'package:firebase/firebase.dart';
void main() {
initializeApp(
apiKey: "YourApiKey",
authDomain: "YourAuthDomain",
databaseURL: "YourDatabaseUrl",
projectId: "YourProjectId",
storageBucket: "YourStorageBucket");
Database database = database();
DatabaseReference ref = database.ref("messages");
ref.onValue.listen((e) {
DataSnapshot datasnapshot = e.snapshot;
// Do something with datasnapshot
});
}
import 'package:firebase/firebase.dart';
import 'package:firebase/firestore.dart' as fs;
void main() {
initializeApp(
apiKey: "YourApiKey",
authDomain: "YourAuthDomain",
databaseURL: "YourDatabaseUrl",
projectId: "YourProjectId",
storageBucket: "YourStorageBucket");
fs.Firestore firestore = firestore();
fs.CollectionReference ref = firestore.collection("messages");
ref.onSnapshot.listen((querySnapshot) {
querySnapshot.docChanges.forEach((change) {
if (change.type == "added") {
// Do something with change.doc
}
});
});
}
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);
...
}
You can find more examples on realtime database, auth, storage and firestore in the example folder.
Demo app which uses Google login, realtime database and storage.
You need to ensure a couple of things before tests and examples in this library are run.
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.
No special action needed here.
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:
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.
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 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.
If you find a bug, please file an issue.
Added support for Firebase Cloud Messaging.
Updated tested/documented Firebase JS API 4.10.1
.
BREAKING Firestore Blob
is no longer wrapped. It is now just the raw
interop object.
fromUint8List
static function is now
fromUint8Array
– since it maps to the source JS function.Blob
for value storage was broken until this change, so a we're
not doing a major version update.Added isEqual
API to Blob
, GeoPoint
, FieldValue
, and FieldPath
.
DocumentReference
and GeoPoint
as a field values in a document.4.8.1
.metadata
property to User
.isNewUser
property to AdditionalUserInfo
.Auth
library which function the same as their counterparts but return a Future
that
resolves with a UserCredential
instead of a User
. These methods will be eventually renamed to replace the older
methods.createUserAndRetrieveDataWithEmailAndPassword
signInAndRetrieveDataWithCustomToken
signInAndRetrieveDataWithEmailAndPassword
signInAnonymouslyAndRetrieveData
lib/src/
files that are not meant for consumptions outside this
package.4.4.0
.languageCode
property to Auth
.useDeviceLanguage
method.sendEmailVerification
and sendPasswordResetEmail
have
optional ActionCodeSettings
parameter.Persistence
state via setPersistence
method on Auth
class.4.2.0
.toJson
to DataSnapshot
and Query
. Auth
:PhoneAuthProvider
and RecaptchaVerifier
.User
:phoneNumber
property to the UserInfo
.linkWithPhoneNumber
, updatePhoneNumber
and
reauthenticateWithPhoneNumber
methods.PhoneAuthProvider
functionality in
example/auth_phone
.Upgraded to Firebase JS API 4.1.3
.
Breaking changes
Auth.onAuthStateChanged
is now User
. AuthEvent
has been
removed.Removed deprecated APIs:
User
link
method in favor of linkWithCredential
.reauthenticate
method in favor of reauthenticateWithCredential
.AuthCredential
provider
property in favor of providerId
.User
: added getIdToken
, reauthenticateAndRetrieveDataWithCredential
,
linkAndRetrieveDataWithCredential
, and toJson()
.
Auth
: added signInAndRetrieveDataWithCredential
and onIdTokenChanged
.
1.21.0
– required to use generic method syntax. The FirebaseJsNotLoadedException
is thrown when the firebase.js script is
not included in the html file.
Fix to support dartdevc
.
3.8.0
and 3.9.0
in auth
library:User
link
method in favor of linkWithCredential
.reauthenticate
method in favor of
reauthenticateWithCredential
.reauthenticateWithPopup
and reauthenticateWithRedirect
methods.UserCredential
operationType
property.AuthCredential
provider
property in favor of providerId
.app.storage()
has now an optional storage bucket parameter.FirebaseClientException
if there are request failures in
firebase_io.dart
.addScope
and setCustomParameters
methods return types.pkg/func
.Updated documentation and tests to reference the latest JS release: 3.7.2
Improvements to README.md
crypto
2.0.0.Strong-mode clean.
Doc fixes.
priority
in set operations.Support latest version of pkg/crypto
Support latest version of firebase.js
- 2.4.2
FirebaseClient.post
to use POST
.FirebaseClient.post
to firebase_io.dart
.Firebase.ServerValue.TIMESTAMP
constantonComplete
argument to Firebase.push
.Fix an issue calling push
with a Map
.
Fixed the return type of Firebase.onAuth
. Also made the returned Stream
asynchronous.
Added anonymous
constructor to FirebaseClient
.
Added firebase_io.dart
library.
createFirebaseJwtToken
can be used for authentication.FirebaseClient
class is a simple wrapper for the Firebase REST
API.Added encodeKey
and decodeKey
methods to firebase.dart
and firebas_io.dart
. Convenience methods for dealing with key values with
disallowed characters.
Removed deprecated name
property on Firebase
and Snapshot
.
Use key
instead`.
Removed deprecated limit
method on Firebase
.
Use limitToFirst
and limitToLast
instead.
Added authWithOAuthToken()
Changed return value of auth methods to return a native dart Map object containing all authData. This is a breaking change.
Updated for Firebase api v2.2.2
Deprecated name
getter on Firebase and DataSnapshot
Added key
getter on Firebase and DataSnapshot, replacing name
Added changeEmail()
Added authAnonymously(), authWithOAuthPopup(), authWithOAuthRedirect()
Added getAuth() and onAuth() listener
Added orderByChild(), orderByKey(), orderByValue(), orderByPriority()
Added equalTo(), limitToFirst(), limitToLast()
Deprecated limit
on Query object
Added exists
getter to DataSnapshot
Added several tests
authWithCustomToken
method (thanks to rayk)auth
firebase.js
link.A number of breaking changes and updates.
A number of methods are now properties.
Fixed up tests.
Cleaned up library structure.
Add this to your package's pubspec.yaml file:
dependencies:
firebase: "^4.4.0"
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:firebase/firebase.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
4.4.0 | Mar 4, 2018 |
|
|
4.3.1 | Jan 11, 2018 |
|
|
4.3.0 | Jan 5, 2018 |
|
|
4.2.0+1 | Dec 9, 2017 |
|
|
4.2.0 | Dec 9, 2017 |
|
|
4.1.0 | Aug 3, 2017 |
|
|
4.0.0 | Jul 17, 2017 |
|
|
3.2.0 | Jun 12, 2017 |
|
|
3.1.0 | Apr 27, 2017 |
|
|
3.0.2 | Apr 17, 2017 |
|
|
We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
95 | / 100 |
Health:
Code health derived from static analysis.
[more]
|
100 | / 100 |
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
99 | / 100 |
Overall score:
Weighted score of the above.
[more]
|
97 |
Detected platforms: web, other
Primary library:
package:firebase/firebase.dart
with components:js
.
Fix analysis and formatting issues.
Analysis or formatting checks reported 1 error 4 hints.
Strong-mode analysis of
lib/src/assets/assets.dart
failed with the following error:line: 4 col: 8
Target of URI doesn't exist: 'package:service_worker/worker.dart'.Strong-mode analysis of
lib/firebase_io.dart
gave the following hint:line: 72 col: 22
'JSON' is deprecated and shouldn't be used.Similar analysis of the following files failed:
lib/src/assets/assets_io.dart
(hint)
The description is too short.
Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.
Maintain an example.
None of the files in your
example/
directory matches a known example patterns. Common file name patterns include:main.dart
,example.dart
or you could also usefirebase.dart
.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.21.0 <2.0.0 | ||
browser | ^0.10.0 | 0.10.0+3 | |
func | >=0.1.0 <2.0.0 | 1.0.0 | |
http | ^0.11.3 | 0.11.3+16 | |
js | ^0.6.0 | 0.6.1 | |
Transitive dependencies | |||
async | 2.0.6 | ||
charcode | 1.1.1 | ||
collection | 1.14.9 | ||
http_parser | 3.1.1 | ||
source_span | 1.4.0 | ||
string_scanner | 1.0.2 | ||
typed_data | 1.1.5 | ||
Dev dependencies | |||
googleapis_auth | ^0.2.3+5 | ||
path | ^1.3.9 | 1.5.1 | |
service_worker | ^0.1.2 | ||
test | ^0.12.17 |