flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_core] `FirebasePluginPlatform` should not extend `PlatformInterface`, `verifyExtends` is never called

Open collinjackson opened this issue 3 years ago • 3 comments

Bug report

FirebasePluginPlatform contains dead code. It should be renamed to FirebasePlugin and should not extend PlatformInterface.

Reasoning: FirebasePluginPlatform.verifyExtends is not ever called. There is no reason for FirebasePluginPlatform to be a PlatformInterface. Having it extend PlatformInterface is fragile because if a method were ever added to FirebasePluginPlatform or PlatformInterface, it could break compatibility with libraries that are using these classes with implements.

Steps to reproduce

class CustomFirebaseAppCheck implements FirebaseAppCheck {
  CustomFirebaseAppCheck() { ... }
  @override
  final FirebaseApp app;
  @override
  Future<void> activate({String? webRecaptchaSiteKey}) { ... }
  @override
  Future<String?> getToken([bool? forceRefresh]) { ... }
  @override
  Future<void> setTokenAutoRefreshEnabled(bool isTokenAutoRefreshEnabled) { ... }
  @override
  Stream<String?> get onTokenChange { ... }
}

Everything would work initially, but minor updates such as new methods added to FirebasePluginPlatform would cause the plugin to fail to compile.

Expected behavior

  • Remove FirebasePluginPlatform.verifyExtends, which is dead code.
  • FirebasePluginPlatform should not extend PlatformInterface. Subclasses of PlatformInterface are not part of the app-facing plugin interface.
  • Rename FirebasePluginPlatform to FirebasePlugin. (Optionally, provide a soft-deprecated compatibility shim FirebasePluginPlatform that extends FirebasePlugin so that this isn't a breaking change.) Update every plugin's app-facing class to extend this new FirebasePlugin class. This is to make it clear that the class is exposed to apps, unlike platform classes.

Additional context

Related issues: https://github.com/firebase/flutterfire/issues/8095 https://github.com/firebase/flutterfire/issues/8096

collinjackson avatar Jun 21 '22 20:06 collinjackson

/cc @russellwheatley

darshankawar avatar Jun 22 '22 07:06 darshankawar

Hello @collinjackson For AppCheck the instance is only a getter

 /// Returns an instance using the default [FirebaseApp].
  static FirebaseAppCheck get instance {
    _instance ??= FirebaseAppCheck._(app: Firebase.app());
    return _instance!;
  }

Moreover, the underlying FirebaseAppCheckPlatform is not exported from the user-facing package. I'm not sure if you used the correct package as an example?

Lyokone avatar Oct 12 '22 09:10 Lyokone

I've updated the issue description to remove the part about instance. I think this is still a valid bug however. Please take another look.

collinjackson avatar Oct 17 '22 14:10 collinjackson