Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

## 3.0.0

Non Nullable By Default (NNBD)
Bump sdk to 2.12.0

## 2.1.0

Upgraded to support firebase-admin Messaging features to send cloud message payloads to device, topic, all, multicast, and subscribe/unsubscribe from topic.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ dev dependencies to your `pubspec.yaml`:

```yaml
dev_dependencies:
build_runner: ^1.0.0
build_node_compilers: ^0.2.0
build_runner: ^2.0.0
build_node_compilers: ^1.0.0
```

Next, create `build.yaml` file with following contents:
Expand Down
2 changes: 1 addition & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ main() async {
final serviceAccountKeyFilename = '/absolute/path/to/service-account.json';
final admin = FirebaseAdmin.instance;
final cert = admin.certFromPath(serviceAccountKeyFilename);
final app = admin.initializeApp(new AppOptions(
final app = admin.initializeApp(AppOptions(
credential: cert,
databaseURL: "YOUR_DB_URL",
));
Expand Down
2 changes: 1 addition & 1 deletion lib/firebase_admin_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/// Future main() async {
/// var admin = FirebaseAdmin.instance;
/// var cert = admin.certFromPath(serviceAccountKeyFilename);
/// var app = admin.initializeApp(new AppOptions(
/// var app = admin.initializeApp(AppOptions(
/// credential: cert,
/// databaseUrl: "YOUR_DB_URL",
/// ));
Expand Down
28 changes: 13 additions & 15 deletions lib/src/admin.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2017, Anatoly Pulyaevskiy. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'package:meta/meta.dart';

import 'app.dart';
import 'bindings.dart' as js;

Expand All @@ -12,10 +10,10 @@ import 'bindings.dart' as js;
/// with [initializeApp] method.
class FirebaseAdmin {
final js.FirebaseAdmin _admin;
final Map<String, App> _apps = new Map();
final Map<String, App> _apps = <String, App>{};

static FirebaseAdmin get instance => _instance ??= new FirebaseAdmin._();
static FirebaseAdmin _instance;
static FirebaseAdmin get instance => _instance ??= FirebaseAdmin._();
static FirebaseAdmin? _instance;

FirebaseAdmin._() : _admin = js.admin;

Expand All @@ -38,7 +36,7 @@ class FirebaseAdmin {
/// privateKey: 'your-private-key',
/// );
/// var app = FirebaseAdmin.instance.initializeApp(
/// new AppOptions(
/// AppOptions(
/// credential: certificate,
/// databaseURL: 'https://your-database.firebase.io')
/// );
Expand All @@ -47,30 +45,30 @@ class FirebaseAdmin {
/// * [App]
/// * [cert]
/// * [certFromPath]
App initializeApp([js.AppOptions options, String name]) {
App initializeApp([js.AppOptions? options, String? name]) {
if (options == null && name == null) {
// Special case for default app with Application Default Credentials.
name = js.defaultAppName;
if (!_apps.containsKey(name)) {
_apps[name] = new App(_admin.initializeApp());
_apps[name] = App(_admin.initializeApp());
}
return _apps[name];
return _apps[name]!;
}

name ??= js.defaultAppName;
if (!_apps.containsKey(name)) {
_apps[name] = new App(_admin.initializeApp(options, name));
_apps[name] = App(_admin.initializeApp(options, name));
}
return _apps[name];
return _apps[name]!;
}

/// Creates [App] certificate.
js.Credential cert({
@required String projectId,
@required String clientEmail,
@required String privateKey,
required String projectId,
required String clientEmail,
required String privateKey,
}) {
return _admin.credential.cert(new js.ServiceAccountConfig(
return _admin.credential.cert(js.ServiceAccountConfig(
project_id: projectId,
client_email: clientEmail,
private_key: privateKey,
Expand Down
18 changes: 8 additions & 10 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,21 @@ class App {
js.AppOptions get options => nativeInstance.options;

/// Gets the [Auth] service for this application.
Auth auth() => _auth ??= new Auth(nativeInstance.auth());
Auth _auth;
Auth auth() => _auth ??= Auth(nativeInstance.auth());
Auth? _auth;

/// Gets Realtime [Database] client for this application.
Database database() =>
_database ??= new Database(this.nativeInstance.database(), this);
Database _database;
_database ??= Database(this.nativeInstance.database(), this);
Database? _database;

/// Gets [Firestore] client for this application.
Firestore firestore() =>
_firestore ??= new Firestore(nativeInstance.firestore());
Firestore _firestore;
Firestore firestore() => _firestore ??= Firestore(nativeInstance.firestore());
Firestore? _firestore;

/// Gets [Messaging] client for this application.
Messaging messaging() =>
_messaging ??= new Messaging(nativeInstance.messaging());
Messaging _messaging;
Messaging messaging() => _messaging ??= Messaging(nativeInstance.messaging());
Messaging? _messaging;

/// Renders this app unusable and frees the resources of all associated
/// services.
Expand Down
9 changes: 5 additions & 4 deletions lib/src/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ class Auth {
/// Returns a [Future] containing a custom token string for the provided [uid]
/// and payload.
Future<String> createCustomToken(String uid,
[Map<String, String> developerClaims]) =>
[Map<String, String>? developerClaims]) =>
promiseToFuture(
nativeInstance.createCustomToken(uid, jsify(developerClaims)));
nativeInstance.createCustomToken(uid, jsify(developerClaims as Object)),
);

/// Creates a new user.
Future<UserRecord> createUser(CreateUserRequest properties) =>
Expand All @@ -67,7 +68,7 @@ class Auth {
/// and starting from the offset as specified by [pageToken].
///
/// This is used to retrieve all the users of a specified project in batches.
Future<ListUsersResult> listUsers([num maxResults, String pageToken]) {
Future<ListUsersResult> listUsers([num? maxResults, String? pageToken]) {
if (pageToken != null && maxResults != null) {
return promiseToFuture(nativeInstance.listUsers(maxResults, pageToken));
} else if (maxResults != null) {
Expand Down Expand Up @@ -120,7 +121,7 @@ class Auth {
/// of [DecodedIdToken]; otherwise, the future is completed with an error.
/// An optional flag can be passed to additionally check whether the ID token
/// was revoked.
Future<DecodedIdToken> verifyIdToken(String idToken, [bool checkRevoked]) {
Future<DecodedIdToken> verifyIdToken(String idToken, [bool? checkRevoked]) {
if (checkRevoked != null) {
return promiseToFuture(
nativeInstance.verifyIdToken(idToken, checkRevoked));
Expand Down
Loading