Skip to content
Closed
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
10 changes: 7 additions & 3 deletions packages/firebase_core/firebase_core/lib/firebase_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
// found in the LICENSE file.

import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
hide MethodChannelFirebaseApp, MethodChannelFirebase;
hide MethodChannelFirebaseApp;
import 'package:flutter/foundation.dart';

export 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
show FirebaseOptions, defaultFirebaseAppName, FirebaseException;
show
FirebaseApp,
FirebaseException,
FirebaseOptions,
FirebaseService,
defaultFirebaseAppName;

part 'src/firebase.dart';
part 'src/firebase_app.dart';
part 'src/port_mapping.dart';
22 changes: 18 additions & 4 deletions packages/firebase_core/firebase_core/lib/src/firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,26 @@ class Firebase {
static FirebasePlatform? delegatePackingProperty;

static FirebasePlatform get _delegate {
return delegatePackingProperty ??= FirebasePlatform.instance;
final delegate = delegatePackingProperty;
if (delegate != null) {
return delegate;
}

// The platform interface cannot depend on the `MethodChannel`
// implementation (it has to stay usable without Flutter), which is why the
// default implementation is installed lazily here instead. Platform
// implementations register themselves, for example `FirebaseCoreWeb` does
// so from `registerWith`, in which case they are kept as is.
if (!FirebasePlatform.isRegistered) {
FirebasePlatform.instance = MethodChannelFirebase();
}

return delegatePackingProperty = FirebasePlatform.instance;
}

/// Returns a list of all [FirebaseApp] instances that have been created.
static List<FirebaseApp> get apps {
return _delegate.apps.map(FirebaseApp._).toList(growable: false);
return _delegate.apps.map(FirebaseApp.fromPlatform).toList(growable: false);
}

/// Initializes a new [FirebaseApp] instance by [name] and [options] and
Expand Down Expand Up @@ -81,7 +95,7 @@ class Firebase {
options: resolvedOptions,
);

return FirebaseApp._(app);
return FirebaseApp.fromPlatform(app);
}

/// Returns a [FirebaseApp] instance.
Expand All @@ -91,7 +105,7 @@ class Firebase {
static FirebaseApp app([String name = defaultFirebaseAppName]) {
FirebaseAppPlatform app = _delegate.app(name);

return FirebaseApp._(app);
return FirebaseApp.fromPlatform(app);
}

// TODO(rrousselGit): remove ==/hashCode
Expand Down
12 changes: 12 additions & 0 deletions packages/firebase_core/firebase_core_common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 0.1.0

- Initial release.
- Pure Dart types and platform interfaces extracted from
`firebase_core_platform_interface` (`FirebaseApp`, `FirebaseAppPlatform`,
`FirebaseOptions`, `FirebaseException`, `FirebasePlatform`, `FirebasePlugin`
and the shared exception helpers), so that Firebase Core platform
implementations can be consumed outside of Flutter.
- `FirebasePlatform.instance` no longer defaults to the `MethodChannel`
implementation: implementations must register themselves (`FirebaseCoreWeb`
does so from `registerWith`) and `FirebasePlatform.isRegistered` allows
checking whether that happened.
27 changes: 27 additions & 0 deletions packages/firebase_core/firebase_core_common/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 changes: 14 additions & 0 deletions packages/firebase_core/firebase_core_common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# firebase_core_common

Pure Dart shared types and platform interfaces used by
[`firebase_core`](https://pub.dev/packages/firebase_core) and its platform
implementations.

This package contains no Flutter dependency and never imports `package:flutter/*`
(neither directly nor transitively). It exists so that platform implementations
such as [`firebase_core_web`](https://pub.dev/packages/firebase_core_web) can be
used outside of Flutter, for example in pure Dart web applications.

It is not intended to be used directly by end users. The Flutter facing API is
exposed by `firebase_core`, and `firebase_core_platform_interface` re-exports
this package for backwards compatibility.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2026, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// Pure Dart shared types and platform interfaces for Firebase Core.
///
/// This library must never import `package:flutter/*` or any library which
/// does, so that Firebase Core platform implementations (such as
/// `firebase_core_web`) can be used outside of Flutter, for example in
/// pure Dart web applications.
///
/// `firebase_core_platform_interface` re-exports this library, so importing
/// that package (directly or through `firebase_core`) keeps giving access to
/// exactly the same types.
library;

export 'src/default_firebase_app_name.dart';
export 'src/firebase_app.dart';
export 'src/firebase_core_exceptions.dart';
export 'src/firebase_exception.dart';
export 'src/firebase_options.dart';
export 'src/platform_interface/platform_interface_firebase.dart';
export 'src/platform_interface/platform_interface_firebase_app.dart';
export 'src/platform_interface/platform_interface_firebase_plugin.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2026, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// The default Firebase application name.
const String defaultFirebaseAppName = '[DEFAULT]';
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of '../firebase_core.dart';
import 'firebase_options.dart';
import 'platform_interface/platform_interface_firebase_app.dart';

/// Represents a single Firebase app instance.
///
/// You can get an instance by calling [Firebase.app()].
class FirebaseApp {
/// Creates a [FirebaseApp] from a [FirebaseAppPlatform] delegate.
///
/// This is not intended to be used directly. On Flutter, use
/// `Firebase.initializeApp()` or `Firebase.app()` instead. When using the
/// platform interfaces directly, for example outside of Flutter, wrap the
/// result of [FirebasePlatform.initializeApp] with this constructor.
factory FirebaseApp.fromPlatform(FirebaseAppPlatform delegate) =>
FirebaseApp._(delegate);

/// A [FirebaseApp] instance can only be accessed from a call to `app()` on
/// [FirebaseCore].
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of '../firebase_core_platform_interface.dart';
import 'default_firebase_app_name.dart';
import 'firebase_exception.dart';

/// Throws a consistent cross-platform error message when usage of an app occurs but
/// no app has been created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of '../firebase_core_platform_interface.dart';
import 'package:meta/meta.dart';

/// A generic class which provides exceptions in a Firebase-friendly format
/// to users.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: deprecated_member_use_from_same_package
part of '../firebase_core_platform_interface.dart';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';

/// The options used to configure a Firebase app.
///
Expand Down Expand Up @@ -53,29 +53,6 @@ class FirebaseOptions {
this.appGroupId,
});

/// Named constructor to create [FirebaseOptions] from a the response of Pigeon channel.
///
/// This constructor is used when platforms cannot directly return a
/// [FirebaseOptions] instance, for example when data is sent back from a
/// [MethodChannel].
FirebaseOptions.fromPigeon(CoreFirebaseOptions options)
: apiKey = options.apiKey,
appId = options.appId,
messagingSenderId = options.messagingSenderId,
projectId = options.projectId,
authDomain = options.authDomain,
databaseURL = options.databaseURL,
storageBucket = options.storageBucket,
measurementId = options.measurementId,
trackingId = options.trackingId,
deepLinkURLScheme = options.deepLinkURLScheme,
androidClientId = options.androidClientId,
iosClientId = options.iosClientId,
iosBundleId = options.iosBundleId,
appGroupId = options.appGroupId,
recaptchaSiteKey =
''; // Placeholder to coordinate with fluttefire cli current operation.

/// Returns a copy of this FirebaseOptions with the given fields replaced with
/// the new values.
FirebaseOptions copyWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of '../../firebase_core_platform_interface.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import '../default_firebase_app_name.dart';
import '../firebase_exception.dart';
import '../firebase_options.dart';
import 'platform_interface_firebase_app.dart';

/// The interface that implementations of `firebase_core` must extend.
///
Expand All @@ -19,15 +24,43 @@ abstract class FirebasePlatform extends PlatformInterface {

static final Object _token = Object();

/// Whether a [FirebasePlatform] implementation has been registered.
///
/// Implementations register themselves by setting [FirebasePlatform.instance],
/// usually from their `registerWith` method which is called by the Flutter
/// plugin registrant (or manually when running outside of Flutter).
static bool get isRegistered => _instance != null;

/// The default instance of [FirebasePlatform] to use.
///
/// Platform-specific plugins should override this with their own class
/// Platform-specific plugins should set this with their own class
/// that extends [FirebasePlatform] when they register themselves.
///
/// Defaults to [MethodChannelFirebase].
static FirebasePlatform get instance => _instance;
/// Throws a [FirebaseException] if no implementation has been registered yet.
/// On Flutter, `firebase_core` registers its `MethodChannel` implementation
/// before the first usage of the `Firebase` API. Other platforms must call
/// the `registerWith` method of their implementation, for example
/// `FirebaseCoreWeb.registerWith(null)` on web.
static FirebasePlatform get instance {
final FirebasePlatform? instance = _instance;

if (instance == null) {
throw FirebaseException(
plugin: 'core',
code: 'no-platform-implementation',
message: 'No Firebase Core platform implementation has been '
'registered.\n\nIf you are using Flutter, this usually means that '
'the platform you are running on is not supported, or that '
'`Firebase.initializeApp()` has not been called yet.\n\nIf you are '
'not using Flutter, register your implementation manually, for '
'example by calling `FirebaseCoreWeb.registerWith(null)` on web.',
);
}

return instance;
}

static FirebasePlatform _instance = MethodChannelFirebase();
static FirebasePlatform? _instance;

static set instance(FirebasePlatform instance) {
PlatformInterface.verify(instance, _token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of '../../firebase_core_platform_interface.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import '../default_firebase_app_name.dart';
import '../firebase_options.dart';

/// A class storing the name and options of a Firebase app.
///
Expand All @@ -26,7 +29,7 @@ class FirebaseAppPlatform extends PlatformInterface {
final FirebaseOptions options;

/// Returns whether this instance is the default Firebase app.
bool get _isDefault => name == defaultFirebaseAppName;
bool get isDefault => name == defaultFirebaseAppName;

/// Returns true if automatic data collection is enabled for this app.
bool get isAutomaticDataCollectionEnabled {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of '../../firebase_core_platform_interface.dart';

/// The base class that other FlutterFire plugins must extend.
///
/// This class provides access to common plugin properties and constants which
Expand All @@ -21,6 +19,24 @@ abstract class FirebasePlugin {
/// requires that the value is synchronously available for use after initialization.
static Map<dynamic, dynamic> _constantsForPluginApps = {};

/// Registers the plugin [constants] of [appName].
///
/// Platform implementations call this once core has been initialized, so
/// that the constants are synchronously available to plugins afterwards.
static void registerConstantsForApp(
String appName,
Map<dynamic, dynamic>? constants,
) {
if (constants != null) {
_constantsForPluginApps[appName] = constants;
}
}
Comment thread
cedvdb marked this conversation as resolved.
Resolved

/// Removes the constants registered for the plugins of [appName].
static void removeConstantsForApp(String appName) {
_constantsForPluginApps.remove(appName);
}

final String _appName;

final String _methodChannelName;
Expand Down
21 changes: 21 additions & 0 deletions packages/firebase_core/firebase_core_common/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: firebase_core_common
description: Pure Dart shared types and platform interfaces used by firebase_core
and its platform implementations.
homepage: https://firebase.google.com/docs/flutter/setup
repository: https://github.com/firebase/flutterfire/tree/main/packages/firebase_core/firebase_core_common
version: 0.1.0
resolution: workspace
topics:
- firebase
- core

environment:
sdk: '^3.6.0'

dependencies:
collection: ^1.0.0
meta: ^1.8.0
plugin_platform_interface: ^2.1.3

dev_dependencies:
test: ^1.25.0
Loading
Loading