# firebase 7.2.0

Firebase libraries for Dart on the web and server




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'firebase:7.2.0'
```
Published: 2020-01-10T01:10:03.781006Z
Expected archive SHA-256: d9f65b8050371b176b7f3100033c921f6b42b52f9ea991b66ab4769c23b31e85
Discontinued upstream.
Available in cache; verification: upstream_checksum
## Direct dependencies
- http: >=0.11.3 <0.13.0
- http_parser: ^3.0.0
- js: ^0.6.0

## Package README (untrusted upstream documentation)
[![Build Status](https://travis-ci.org/FirebaseExtended/firebase-dart.svg?branch=master)](https://travis-ci.org/FirebaseExtended/firebase-dart)

**NOTE:** This package provides three libraries:

* Browser-based applications:
  [`package:firebase/firebase.dart` and `package:firebase/firestore.dart`](#using-this-package-for-browser-applications)

  A wrapper over the [Firebase JS API](https://firebase.google.com/docs/reference/js/).

* Dart VM and Fuchsia:
  [`package:firebase/firebase_io.dart`](#using-this-package-with-the-dart-vm-and-fuchsia)
  
  A lightly maintained wrapper over the
  [Firebase Database REST API](https://firebase.google.com/docs/reference/rest/database/).
  *Contributions to expand support to the other REST APIs are appreciated!* 

### Other platforms

* Flutter: [FlutterFire plugins](https://github.com/flutter/plugins/blob/master/FlutterFire.md)

* Node (via dart2js): [Anatoly Pulyaevskiy](https://github.com/pulyaevskiy) has
  been working on unofficial wrappers.
  * [package:firebase_admin_interop](https://pub.dev/packages/firebase_admin_interop)
  * [package:firebase_functions_interop](https://pub.dev/packages/firebase_functions_interop)

## Firebase Configuration
You can find more information on how to use Firebase on the
[Getting started](https://firebase.google.com/docs/web/setup) page.

Don't forget to setup correct **rules** for your
[realtime database](https://firebase.google.com/docs/database/security/),
[storage](https://firebase.google.com/docs/storage/security/) and/or 
[firestore](https://firebase.google.com/docs/firestore/security/get-started)
in the Firebase console. 

If you want to use [Firestore](https://firebase.google.com/docs/firestore/quickstart), 
you need to enable it in the Firebase console and include the
[additional js script](#do-you-need-to-use-firestore).

Authentication also has to be enabled in the Firebase console.
For more info, see the
[next section](#before-tests-and-examples-are-run)
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:

```html
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.6.1/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](example/firestore).

### Real-time Database Example 

```dart
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

```dart
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](https://firebase.google.com/docs/reference/rest/database/).

The dart:io client also supports authentication. See the documentation on how to get
[auth credentials](https://firebase.google.com/docs/reference/rest/database/user-auth).

```dart
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](https://github.com/FirebaseExtended/firebase-dart/tree/master/example)
folder.

## Dart Dev Summit 2016 demo app

[Demo app](https://github.com/Janamou/firebase-demo)
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`](https://github.com/FirebaseExtended/firebase-dart/tree/master/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:

```json
{
  "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](https://firebase.google.com/docs/database/security/). 

### 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](https://firebase.google.com/docs/firestore/security/get-started). 

You also need to include the additional `firebase-firestore.js` script.
See [more info](#do-you-need-to-use-firestore).

### 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](https://firebase.google.com/docs/storage/web/list-files) 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](https://firebase.google.com/docs/storage/security/). 


### 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:

```html
<script src="https://www.gstatic.com/firebasejs/7.6.1/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:

```dart
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](https://firebase.google.com/docs/remote-config) 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.


## Bugs

If you find a bug, please file an
[issue](https://github.com/FirebaseExtended/firebase-dart/issues).

## Changelog
## 7.2.0

- Added [Remote Config](https://firebase.google.com/docs/remote-config) support.
  - See the top-level `remoteConfig` function and the related `RemoteConfig`
    class.
- Added back `AuthProvider` and made `OAuthProvider` a subtype.

## 7.1.0

- Added `Auth.fetchSignInMethodsForEmail` and `Auth.isSignInWithEmailLink`.

## 7.0.0

- **BREAKING** renamed `AuthCredential` into `OAuthCredential` to align with JS API
- **BREAKING** removed deprecated Firestore `Settings.timestampsInSnapshots`. 
- Added support for functions.
- Added `idToken`, `accessToken` and `secret` to `OAuthCredential`
- Added support for Email Link authentication.
- Firestore `Settings` added `cacheSizeBytes`, `host`, and `ssl` properties.
- Added `measurementId` and `appId` to `FirebaseOptions` (both required for analytics)
- Added analytics and performance interop
- Added `User.getIdTokenResult`.
- Removed long-deprecated `Auth.fetchProvidersForEmail` function.
- Updated documented JS library from `6.6.1` of the JS API to `7.4.0`.

## 6.0.0

- **BREAKING** Removed and renamed members across `auth` and `firestore` to
  align with v6 changes to
  [JS API](https://firebase.google.com/support/release-notes/js#version_600_-_may_7_2019).
- **BREAKING** The `Promise` polyfil has been removed from the JS SDK. Users
  will have to include their own polyfil for `Promise`. 
- **BREAKING** All of the setters on `FirebaseError` have been removed.

- Added `serverResponse` getter to `FirebaseError`.
- Added `FieldValue.increment` static function.
- Added support for storage List API.
- Added support for firestore `collectionGroup`.
- Added `OAuthProvider`.

## 5.0.4

- Require at least Dart 2.1.0.
- Updated documented JS library from `5.5.2` of the JS API to `5.10.1`.

## 5.0.3

- Add support for firestore `FieldValue.arrayUnion()` and `FieldValue.arrayRemove()`
- Fix a number of issues in interop.
- Support the latest `pkg:http`.

## 5.0.2

* Updated documented JS library from `5.1.0` of the JS API to `5.5.2`.

* Fixed issues with canceled subscriptions in Database `Query`.

## 5.0.1

* README updates.

## 5.0.0

* Updated from `4.13.0` of the JS API to `5.1.0`.

* Auth
  * `getToken` has been removed.
  * `linkWithCredential`, `fetchProvidersForEmail`, `signinWithCredential`, and 
    `reauthenticateWithCredential` have been deprecated.
  * `createUserWithEmailAndPassword`, `signInAnonymously`, 
    `signinWithCustomToken`, and `signInWithEmailAndPassword` all return 
    `UserCredential` instead of `User`.

* Firestore
  * `QuerySnapshot.docChanges` is now a function.
  * `timestampInSnapshots` is set to `true` by default.

* Storage
  * `downloadURLs` and `downloadURL` have been removed.

## 4.5.1

* Require at least Dart SDK `2.0.0-dev.61`.

* Simplify promise-Future interop using new `dart:html` API.

* Fixed remaining issues with Dart2 runtime semantics.

## 4.5.0

* Updated tested JS API version to `4.13.0`.
  * Deprecated `downloadURL` and `downloadURLs`. 

* Require at least Dart SDK `2.0.0-dev.36`.

### Firestore

* Moved `setLogLevel` to a top-level method from `Firestore`.
  *Not considering this a breaking change since the method never worked as
  previously exposed.*

* Added `isEqual` to `CollectionReference`, `DocumentSnapshot`,
  `SnapshotMetadata`and `QuerySnapshot`.

* Added `disableNetwork` and `enableNetwork` to `Firestore`

## 4.4.0

* Added support for
  [Firebase Cloud Messaging](https://firebase.google.com/docs/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.
  
  * The only practical change is the `fromUint8List` static function is now
    `fromUint8Array` – since it maps to the source JS function.
  * Usage of `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`. 

## 4.3.1

* Support `DocumentReference` and `GeoPoint` as a field values in a document.

## 4.3.0

* Upgraded to Firebase JS API `4.8.1`.
* Added `metadata` property to `User`.
* Added `isNewUser` property to `AdditionalUserInfo`.
* Updated auth examples and tests with the latest features.
* Added new Firestore library - see [README](README.md) and [example/firestore](example/firestore) on how to use it.
* Added new APIs for the `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`
    
## 4.2.0+1

* Updates to `lib/src/` files that are not meant for consumptions outside this
  package.

## 4.2.0

* Improve the generic types in the interop library.
* Upgraded to Firebase JS API `4.4.0`.
* Added client side localization for email actions, phone authentication SMS 
  messages, OAuth flows and reCAPTCHA verification:
    * Added readable/writable `languageCode` property to `Auth`.
    * Added `useDeviceLanguage` method.
* Added the ability to pass a continue URL/state when triggering a password 
  reset/email verification which gives a user the ability to go back to the app
  after completion.
* Added support for the ability to open these links directly from a mobile app
  instead of a web flow using Firebase Dynamic Links:
    * `sendEmailVerification` and `sendPasswordResetEmail` have 
      optional `ActionCodeSettings` parameter.
* Added `Persistence` state via `setPersistence` method on `Auth` class.
* Updated auth example with the latest features.

## 4.1.0

* Upgraded to Firebase JS API `4.2.0`.
* Added `toJson` to `DataSnapshot` and `Query`. 
* `Auth`:
    * Implemented `PhoneAuthProvider` and `RecaptchaVerifier`.
* `User`:
    * Added `phoneNumber` property to the `UserInfo`.
    * Added `linkWithPhoneNumber`, `updatePhoneNumber` and 
      `reauthenticateWithPhoneNumber` methods.
* New example demonstrating `PhoneAuthProvider` functionality in 
  `example/auth_phone`.
* Added more tests for V4 API.

## 4.0.0

* Upgraded to Firebase JS API `4.1.3`.

* Breaking changes
  * The value in `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`.

## 3.2.1

* Update minimum Dart SDK to `1.21.0` – required to use generic method syntax. 

## 3.2.0

* The `FirebaseJsNotLoadedException` is thrown when the firebase.js script is 
  not included in the html file.
  
* Fix to support `dartdevc`.

## 3.1.0

* Updates from the Firebase `3.8.0` and `3.9.0` in `auth` library:
    * `User`
        * Deprecated `link` method in favor of `linkWithCredential`.
        * Deprecated `reauthenticate` method in favor of
          `reauthenticateWithCredential`.
        * Added new `reauthenticateWithPopup` and `reauthenticateWithRedirect`
          methods.
    * `UserCredential`
        * Added new `operationType` property.
    * `AuthCredential`
        * Deprecated `provider` property in favor of `providerId`.
* The `app.storage()` has now an optional storage bucket parameter.

## 3.0.2

* Throw `FirebaseClientException` if there are request failures in
  `firebase_io.dart`.
* Fix provider's `addScope` and `setCustomParameters` methods return types.
* Support the latest release of `pkg/func`.

## 3.0.1

* Updated documentation and tests to reference the latest JS release: `3.7.2`

* Improvements to `README.md`

## 3.0.0

* Completely rewritten for Firebase v3.

## 0.6.6+3

* Support `crypto` 2.0.0.

## 0.6.6+2

* Strong-mode clean.

* Doc fixes.

## 0.6.6+1

* Support non-integer values for `priority` in set operations.

## 0.6.6

* Support latest version of `pkg/crypto`

* Support latest version of `firebase.js` - 2.4.2

## 0.6.5+1

* Fixed `FirebaseClient.post` to use `POST`.

## 0.6.5

* Added `FirebaseClient.post` to `firebase_io.dart`.

## 0.6.4

* Added `Firebase.ServerValue.TIMESTAMP` constant

## 0.6.3

* Added `onComplete` argument to `Firebase.push`.

## 0.6.2

* Fix an issue calling `push` with a `Map`.

* Fixed the return type of `Firebase.onAuth`. Also made the returned `Stream`
  asynchronous.

## 0.6.1

* Added `anonymous` constructor to `FirebaseClient`.

* Added `firebase_io.dart` library.
  * `createFirebaseJwtToken` can be used for authentication.
  * The `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.

## 0.6.0

* Removed deprecated `name` property on `Firebase` and `Snapshot`.
  Use `key` instead`.

* Removed deprecated `limit` method on `Firebase`.
  Use `limitToFirst` and `limitToLast` instead.

## 0.5.1

* Updated startAt() and endAt() methods. They don't take a
  priority anymore and are meant to be used in conjunction with orderBy*

## 0.5.0

* Added authWithOAuthToken()

* Changed return value of auth methods to return a native dart Map
  object containing all authData. This is a breaking change.

## 0.4.0

* 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

## 0.3.0

* Add createUser(), removeUser() and authWithPassword()
  (thanks to wilsynet)
* AuthResponse.auth was changed to type JsObject

## 0.2.1

* Added new `authWithCustomToken` method (thanks to rayk)
* Deprecate `auth`

## 0.2.0+1

* Updated README to include latest `firebase.js` link.

## 0.2.0

* A number of breaking changes and updates.

* A number of methods are now properties.

## 0.1.1+3

* Fixed up tests.

* Cleaned up library structure.








 
