Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Support for firebase_core interoperating with native code that configures Firebase apps. #478

Merged
merged 11 commits into from
Apr 9, 2018

Conversation

collinjackson
Copy link
Contributor

@collinjackson collinjackson commented Apr 9, 2018

Required for #476

In practice, I doubt anyone would need read the options of an app, it's far more common to set it via configure() than read it. So making this API async doesn't affect the developer much.

An alternative is that we could make the options getter synchronous but throw an exception for the default app unless the developer puts an await FirebaseApp.configure() in their code first.

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

FirebaseApp app = FirebaseApp.getInstance(name);
result.success(asMap(app));
} catch (IllegalStateException ex) {
result.success(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might deserve a comment that we successfully return null here.

} else if ([@"FirebaseApp#appNamed" isEqualToString:call.method]) {
NSString *name = call.arguments;
FIRApp *app = [FIRApp appNamed:name];
result(app.flutterDictionary);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crash if there is no app with that name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Objective-C so it just returns nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. I thought that was only the case with [message passing]. But perhaps property access is just msg passing under the hood?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@@ -6,44 +6,71 @@ part of firebase_core;

class FirebaseApp {
@visibleForTesting
const FirebaseApp({this.name, @required this.options});
const FirebaseApp({@required this.name}) : assert(name != null);

/// Gets the name of this app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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

static Map<String, FirebaseApp> _namedApps = <String, FirebaseApp>{};
/// Gets a copy of the options for this app. These are non-modifiable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, getters should be documented with a noun phrase.

}).then((dynamic _) => _namedApps[name]);
await channel.invokeMethod(
'FirebaseApp#configure',
<String, dynamic>{'name': name, 'options': options?.asMap},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options cannot be null here.

);

setUp(() async {
FirebaseApp.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
switch (methodCall.method) {
case 'FirebaseApp#appNamed':
if (methodCall.arguments != 'testApp') return null;
return <String, dynamic>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be <dynamic, dynamic> with production code.

if (methodCall.arguments != 'testApp') return null;
return <String, dynamic>{
'name': 'testApp',
'options': <String, dynamic>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

'deepLinkURLScheme': 'testDeepLinkURLScheme',
'storageBucket': 'testStorageBucket',
},
};
case 'FirebaseApp#allApps':
return <Map<String, dynamic>>[
<String, dynamic>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these containers.

@collinjackson collinjackson merged commit 989ebbf into flutter:master Apr 9, 2018
slightfoot pushed a commit to slightfoot/plugins that referenced this pull request Jun 5, 2018
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants