Introduction
In addition to the two ways of using dependency_overrides to configure the HarmonyOS adaptation library mentioned in the previous article Existing Flutter projects support HarmonyOS II, if the third-party plug-in itself uses the form of joint plug-ins, you can also add the implementation of the HarmonyOS platform in the following way:
dependencies:
image_picker: ^1.1.2
image_picker_ohos:
git:
url: "https://gitcode.com/openharmony-sig/flutter_packages.git"
path: "packages/image_picker/image_picker_ohos"
This is also a very elegant way, without modifying the code of the plugin, you can directly add the HarmonyOS adaptation library to the project configuration.
What is a Federation Plugin?
Federated plugins is a software package that separates support for different platforms. As a result, federation plug-ins can use separate packages for iOS, Android, the web, and even for automobiles (e.g. IoT devices). In addition to these benefits, it enables domain experts to extend existing platform plugins on the platforms they know best.
The federation plugin requires the following package:
App-oriented packages
The package is a direct dependency of the user to use the plugin. It specifies the APIs used by the Flutter app.
Platform package
One or more packages that contain platform-specific code. App-oriented packages call these platform packages - they won't be included in the app unless they come with some special platform features that the end user needs.
Platform interface package
A package that integrates an app-oriented package with a platform package. The package declares the interfaces that the platform package needs to implement for use by the application-oriented package. Using a single platform interface package ensures that all platform packages implement the same required functionality in their own way.
What is an unintegrated federation plugin?
Conversely, integrated federated plugins, i.e., plugin implementations on a certain platform, are integrated into the main package, which is the "application-oriented package". If the plug-in has already integrated the OHOS implementation, such as FluwX, you can use it directly, and there is no need to add the implementation of the HarmonyOS platform.
If the plugin does not integrate the OHOS implementation, such as image_picker, you need to add the implementation of the HarmonyOS platform. :
This is called "unintegrated federation plugins" (https://docs.flutter.cn/packages-and-plugins/developing-packages#non-endorsed-federated-plugin), and in the above configuration,
image_picker is a federation plugin, here directly use the latest version of the official community, observe the pubspec.yaml file of the plugin, through its structure you can find the characteristics of the federation plugin, the dependencies of the plugin are:
dependencies:
image_picker_platform_interface: ^2.10.0
...
image_picker_android: ^0.8.7
image_picker_ios: ^0.8.8
'image_picker_platform_interface' is an abstraction layer, which defines the platform-related interfaces, the following is the implementation of each platform, by splitting it into packages, loading in a dependent way, then the same principle, you can add another implementation package of the HarmonyOS platform, you can complete the HarmonyOS adaptation, that is, the 'image_picker_ohos' in the above example:
image_picker_ohos:
git:
url: "https://gitcode.com/openharmony-sig/flutter_packages.git"
path: "packages/image_picker/image_picker_ohos"
Precautions
It's important to note that not all plugins are suitable for this approach, and there are two scenarios where they are not:
Plugins are not federated plugins, i.e., all platform implementations are aggregated in a package, which suggests using dependence_override to override plugin dependencies
Although the plug-in is a joint plug-in, but HarmonyOS needs to modify the abstraction layer code, such as using Platform.ohos, an API that only HarmonyOS Flutter SDK has, and it is also recommended to use dependence_override
Top comments (0)