Skip to content

Commit

Permalink
[firebase_core] Migrate to platform_interface (firebase#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Terkelsen authored Nov 21, 2019
1 parent d115762 commit ad5ab7a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 262 deletions.
4 changes: 4 additions & 0 deletions packages/firebase_core/firebase_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.2

* Migrate to `firebase_core_platform_interface`.

## 0.4.1+6

* Update the homepage now that the package structure has changed.
Expand Down
7 changes: 4 additions & 3 deletions packages/firebase_core/firebase_core/lib/firebase_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ library firebase_core;

import 'dart:async';
import 'dart:io' show Platform;
import 'dart:ui' show hashValues;

import 'package:flutter/services.dart';
import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart';
import 'package:meta/meta.dart';

export 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
show FirebaseOptions;

part 'src/firebase_app.dart';
part 'src/firebase_options.dart';
38 changes: 10 additions & 28 deletions packages/firebase_core/firebase_core/lib/src/firebase_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,23 @@ class FirebaseApp {
static final String defaultAppName =
Platform.isIOS ? '__FIRAPP_DEFAULT' : '[DEFAULT]';

@visibleForTesting
static const MethodChannel channel = MethodChannel(
'plugins.flutter.io/firebase_core',
);

/// A copy of the options for this app. These are non-modifiable.
///
/// This getter is asynchronous because apps can also be configured by native
/// code.
Future<FirebaseOptions> get options async {
final Map<String, dynamic> app =
await channel.invokeMapMethod<String, dynamic>(
'FirebaseApp#appNamed',
name,
);
final PlatformFirebaseApp app =
await FirebaseCorePlatform.instance.appNamed(name);
assert(app != null);
return FirebaseOptions.from(app['options']);
return app.options;
}

/// Returns a previously created FirebaseApp instance with the given name,
/// or null if no such app exists.
static Future<FirebaseApp> appNamed(String name) async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<String, dynamic> app =
await channel.invokeMapMethod<String, dynamic>(
'FirebaseApp#appNamed',
name,
);
return app == null ? null : FirebaseApp(name: app['name']);
final PlatformFirebaseApp app =
await FirebaseCorePlatform.instance.appNamed(name);
return app == null ? null : FirebaseApp(name: app.name);
}

/// Returns the default (first initialized) instance of the FirebaseApp.
Expand All @@ -69,22 +55,18 @@ class FirebaseApp {
if (existingApp != null) {
return existingApp;
}
await channel.invokeMethod<void>(
'FirebaseApp#configure',
<String, dynamic>{'name': name, 'options': options.asMap},
);
await FirebaseCorePlatform.instance.configure(name, options);
return FirebaseApp(name: name);
}

/// Returns a list of all extant FirebaseApp instances, or null if there are
/// no FirebaseApp instances.
static Future<List<FirebaseApp>> allApps() async {
final List<dynamic> result = await channel.invokeListMethod<dynamic>(
'FirebaseApp#allApps',
);
final List<PlatformFirebaseApp> result =
await FirebaseCorePlatform.instance.allApps();
return result
?.map<FirebaseApp>(
(dynamic app) => FirebaseApp(name: app['name']),
(PlatformFirebaseApp app) => FirebaseApp(name: app.name),
)
?.toList();
}
Expand Down
150 changes: 0 additions & 150 deletions packages/firebase_core/firebase_core/lib/src/firebase_options.dart

This file was deleted.

4 changes: 3 additions & 1 deletion packages/firebase_core/firebase_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Core, enabling connecting to multiple
Firebase apps.
author: Flutter Team <[email protected]>
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_core/firebase_core
version: 0.4.1+6
version: 0.4.2

flutter:
plugin:
Expand All @@ -12,6 +12,7 @@ flutter:
pluginClass: FirebaseCorePlugin

dependencies:
firebase_core_platform_interface: ^1.0.0
flutter:
sdk: flutter
meta: "^1.0.5"
Expand All @@ -22,6 +23,7 @@ dev_dependencies:
sdk: flutter
flutter_test:
sdk: flutter
mockito: ^4.1.1

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
Expand Down
Loading

0 comments on commit ad5ab7a

Please sign in to comment.