PlatformDependencies class
The services a FirebaseApp needs from the platform it runs on: storage, connectivity and
background events, and the auth and App Check token providers.
Subclass it, override the members you can supply, and pass an instance as dependencies: to
FirebaseApp.withOptions. The app reads each member once, when it is created, so a member
that returns a stream must return the same object every time: keep it in a field. Every member
has a default:
| Member | Default | Who reads it |
|---|---|---|
| onNetworkConnected | always connected | Firestore: true restarts failed streams at once |
| onBackgroundChanged | never in the background | nobody in this repository |
| storage | this object, in memory | FirebaseApp.setAutomaticDataCollectionEnabled |
| authProvider | none: requests carry no token | Firestore |
| appCheckProvider | none: no App Check header | Firestore, FirebaseUserAuth |
| headersBuilder | none | nobody in this repository |
import 'package:firebase_app_dart/firebase_app_dart.dart';
import 'package:firebase_app_dart/platform_dependencies.dart';
import 'package:rxdart/rxdart.dart';
class AppDependencies extends PlatformDependencies {
/// Fed by a connectivity plugin, for example `connectivity_plus`.
final BehaviorSubject<bool> connectivity = BehaviorSubject<bool>.seeded(true);
@override
BehaviorSubject<bool> get onNetworkConnected => connectivity;
}
void main() {
final AppDependencies dependencies = AppDependencies();
FirebaseApp.withOptions(
const FirebaseOptions(
apiKey: '<YOUR_API_KEY>',
appId: '1:1234567890:dart:example',
projectId: 'my-project',
),
dependencies: dependencies,
);
dependencies.connectivity.add(false); // the device went offline
}
- Inheritance
-
- Object
- LocalStorage
- PlatformDependencies
- Implementers
Constructors
- PlatformDependencies()
- Creates the default dependencies: an in-memory LocalStorage, always connected, never in the background, and no token providers.
Properties
- appCheckProvider → AppCheckTokenProvider?
-
Firestore sends the token of this provider in the
x-firebase-appcheckheader of every request. Default null: no App Check header is sent.no setter - authProvider → AuthTokenProvider?
-
The source of the token that Firestore sends with each request. Default null: requests carry
no token, and the security rules see no user.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- headersBuilder → HeaderBuilder?
-
Extra headers for the requests of Firebase services. Default null.
no setter
-
onBackgroundChanged
→ BehaviorSubject<
bool> -
Emits
truewhen the app goes to the background andfalsewhen it comes back.no setter -
onNetworkConnected
→ BehaviorSubject<
bool> -
Emits
truewhen the device has a network connection andfalsewhen it lost it.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storage → LocalStorage
-
Key/value storage that survives a restart of the app. The default is this object, which keeps
the values in memory (get and set).
no setter
Methods
-
get(
String key) → String? -
The value stored in memory under
key, or null.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
set(
String key, String? value) → Future< void> -
Stores
valuein memory underkey; null removes it.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited