Skip to content

Objc class names should have unique prefix for each plugin in flutter/packages #102601

@cyanglaz

Description

@cyanglaz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: contributor-productivityTeam-specific productivity, code health, technical debt.packageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions