Skip to content

Commit ad5ab7a

Browse files
author
Harry Terkelsen
authored
[firebase_core] Migrate to platform_interface (#1472)
1 parent d115762 commit ad5ab7a

File tree

6 files changed

+67
-262
lines changed

6 files changed

+67
-262
lines changed

packages/firebase_core/firebase_core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.2
2+
3+
* Migrate to `firebase_core_platform_interface`.
4+
15
## 0.4.1+6
26

37
* Update the homepage now that the package structure has changed.

packages/firebase_core/firebase_core/lib/firebase_core.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ library firebase_core;
66

77
import 'dart:async';
88
import 'dart:io' show Platform;
9-
import 'dart:ui' show hashValues;
109

11-
import 'package:flutter/services.dart';
10+
import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart';
1211
import 'package:meta/meta.dart';
1312

13+
export 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
14+
show FirebaseOptions;
15+
1416
part 'src/firebase_app.dart';
15-
part 'src/firebase_options.dart';

packages/firebase_core/firebase_core/lib/src/firebase_app.dart

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,23 @@ class FirebaseApp {
1414
static final String defaultAppName =
1515
Platform.isIOS ? '__FIRAPP_DEFAULT' : '[DEFAULT]';
1616

17-
@visibleForTesting
18-
static const MethodChannel channel = MethodChannel(
19-
'plugins.flutter.io/firebase_core',
20-
);
21-
2217
/// A copy of the options for this app. These are non-modifiable.
2318
///
2419
/// This getter is asynchronous because apps can also be configured by native
2520
/// code.
2621
Future<FirebaseOptions> get options async {
27-
final Map<String, dynamic> app =
28-
await channel.invokeMapMethod<String, dynamic>(
29-
'FirebaseApp#appNamed',
30-
name,
31-
);
22+
final PlatformFirebaseApp app =
23+
await FirebaseCorePlatform.instance.appNamed(name);
3224
assert(app != null);
33-
return FirebaseOptions.from(app['options']);
25+
return app.options;
3426
}
3527

3628
/// Returns a previously created FirebaseApp instance with the given name,
3729
/// or null if no such app exists.
3830
static Future<FirebaseApp> appNamed(String name) async {
39-
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
40-
// https://github.com/flutter/flutter/issues/26431
41-
// ignore: strong_mode_implicit_dynamic_method
42-
final Map<String, dynamic> app =
43-
await channel.invokeMapMethod<String, dynamic>(
44-
'FirebaseApp#appNamed',
45-
name,
46-
);
47-
return app == null ? null : FirebaseApp(name: app['name']);
31+
final PlatformFirebaseApp app =
32+
await FirebaseCorePlatform.instance.appNamed(name);
33+
return app == null ? null : FirebaseApp(name: app.name);
4834
}
4935

5036
/// Returns the default (first initialized) instance of the FirebaseApp.
@@ -69,22 +55,18 @@ class FirebaseApp {
6955
if (existingApp != null) {
7056
return existingApp;
7157
}
72-
await channel.invokeMethod<void>(
73-
'FirebaseApp#configure',
74-
<String, dynamic>{'name': name, 'options': options.asMap},
75-
);
58+
await FirebaseCorePlatform.instance.configure(name, options);
7659
return FirebaseApp(name: name);
7760
}
7861

7962
/// Returns a list of all extant FirebaseApp instances, or null if there are
8063
/// no FirebaseApp instances.
8164
static Future<List<FirebaseApp>> allApps() async {
82-
final List<dynamic> result = await channel.invokeListMethod<dynamic>(
83-
'FirebaseApp#allApps',
84-
);
65+
final List<PlatformFirebaseApp> result =
66+
await FirebaseCorePlatform.instance.allApps();
8567
return result
8668
?.map<FirebaseApp>(
87-
(dynamic app) => FirebaseApp(name: app['name']),
69+
(PlatformFirebaseApp app) => FirebaseApp(name: app.name),
8870
)
8971
?.toList();
9072
}

packages/firebase_core/firebase_core/lib/src/firebase_options.dart

Lines changed: 0 additions & 150 deletions
This file was deleted.

packages/firebase_core/firebase_core/pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Core, enabling connecting to multiple
33
Firebase apps.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_core/firebase_core
6-
version: 0.4.1+6
6+
version: 0.4.2
77

88
flutter:
99
plugin:
@@ -12,6 +12,7 @@ flutter:
1212
pluginClass: FirebaseCorePlugin
1313

1414
dependencies:
15+
firebase_core_platform_interface: ^1.0.0
1516
flutter:
1617
sdk: flutter
1718
meta: "^1.0.5"
@@ -22,6 +23,7 @@ dev_dependencies:
2223
sdk: flutter
2324
flutter_test:
2425
sdk: flutter
26+
mockito: ^4.1.1
2527

2628
environment:
2729
sdk: ">=2.0.0-dev.28.0 <3.0.0"

0 commit comments

Comments
 (0)