-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Background
See: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Conventions/Conventions.html
"Objective-C classes must be named uniquely not only within the code that you’re writing in a project, but also across any frameworks or bundles you might be including. As an example, you should avoid using generic class names like ViewController or TextParser because it’s possible a framework you include in your app may fail to follow conventions and create classes with the same names."
The TL;DR is: When different plugins are included in the same flutter app, all the ObjC classes need to have unique name. Because we test and compile plugins independently, it is possible to have classes with the same names in different plugin.
For example, consider ImagePicker plugin and VideoPlayerPlugin. We might create a new ObjcC class in ImagePicker plugin called FLTVideoInfo, and then also create a new ObjC class in the VideoPlayerPlugin with the same name without knowing that the same class exists in ImagePicker plugin. It causes a conflicts when an app includes both plugins to its dependencies.
Proposal
To avoid this issue as much as possible, we can enforce a unique class prefix for each plugin. I will list the current prefix used in all the flutter/plugins and the prefix I suggest to use here:
| Plugin | Current | Proposed | TaskCompleted |
|---|---|---|---|
| Camera | FLT | FCP | |
| GoogleMaps | FLT | FGM | |
| GoogleSignIn | FLT | FSI | |
| ImagePicker | FLT | FIP | |
| InAppPurchase | FIAP | FIA (3 characters are recommanded per ObjC style) | |
| IOSPlatformImages | None | FPI | |
| LocalAuth | FLT | FLA | |
| PathProvider | FLT | FPP | |
| QuickActions | FLT | FQA | |
| SharedPreferences | FLT | FSP | |
| URLLauncher | FLT | FUL | |
| VideoPlayer | FLT | FVP | |
| WebViewFlutter | FLT | FWV |
Limitation
It is possible a plugin that is not authored by the Flutter team contains classes with the exact same name, or the app itself contains a class with the same name. We probably don't have any control over those scenarios, the app developer will be responsible to address these situation case by case.
Enforce and Testing
To enforce all the ObjC classes in the plugins use the correct unique Prefix, we might need a dart script (in plugin tools) to scan all the @interfaces in all .h files under /ios/Classes/ to ensure they are using the correct prefix.