FirebaseDatabase.api constructor
FirebaseDatabase.api(
- RestApi api, {
- FirebaseAccount? account,
Constructs a rawdatabase from the raw api
This constructor creates a database that directly uses a previously created api. The database to connect to and other parameters must be directly configured when created the RestApi.
By default, you have to manually set authentication on the API. However,
if you want the RestApi.idToken to be automatically updated when an
account is updated, you can optionally pass a account to this
constructor. In that case, the database connects to the
FirebaseAccount.idTokenStream
and streams idToken updates to the api.
Note: Typically, you would use one of the other constructors to create the database. Only use this constructor if you can't use the others.
Implementation
FirebaseDatabase.api(
this.api, {
this.account,
}) : rootStore = FirebaseStore<dynamic>.apiCreate(
restApi: api,
subPaths: [],
onDataFromJson: (dynamic json) => json,
onDataToJson: (dynamic data) => data,
onPatchData: (dynamic data, updatedFields) =>
(data as Map<String, dynamic>)..addAll(updatedFields),
) {
if (account != null) {
_idTokenSub = account!.idTokenStream.listen(
(idToken) => api.idToken = idToken,
cancelOnError: false,
);
}
}