flutter_packages_0605:基于 Flutter 生态的 OpenHarmony 平台插件适配项目

开发者可通过本项目在 Flutter 应用中无缝集成常用插件,最小化业务改动获得完整 OpenHarmony 原生能力支持。项目基于 Flutter 社区官方插件库扩展,新增对 OpenHarmony 平台的兼容适配,提供多个已适配插件及使用示例。【此简介由AI生成】

Branch79Tags42

Flutter Packages

Introduction

This repository is an extension of the Flutter community’s official plugin library ([flutter/packages](vscode-file://vscode-app/e:/Microsoft VS Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html)), adding compatibility and adaptation for the OpenHarmony platform. With this repository, developers can seamlessly integrate commonly used plugins into Flutter applications and gain full support for OpenHarmony native capabilities with minimal business changes.

OpenHarmony Compatible Packages

OpenHarmony Compatible Third-Party Libraries

For third-party library issues, please submit an issue to the corresponding repository. For third-party library adaptation requests, please submit an issue to the CPF-Flutter organization.

Contribution Guidelines

This repository employs a multi-branch management strategy. Each third-party library version maintains dedicated dev and release branches.

Branch Type Naming Convention
Dev Branch br_<library-name>-v<version>_ohos_dev
Release Branch br_<library-name>-v<version>_ohos

When contributing code, please adhere to the following process:

  1. Identify the Target Branch: Locate the appropriate dev branch for the third-party library and version you intend to modify.

  2. Develop from the Dev Branch: Fork the repository and create your feature branch from the corresponding dev branch.

  3. Submit Your Pull Request: Open a pull request targeting the dev branch of the respective library version.

Important: Release branches are designated for stable releases only and do not accept direct pull requests. All contributions must be submitted to the appropriate dev branch for the corresponding library version.

Getting Started

Before using the plugins from this repository, please ensure that you have completed the OpenHarmony environment setup for the Flutter SDK.

  • Environment Setup

    Refer to the documentation in the flutter_flutter repository under the section “Environment Configuration”.

  • Example Reference

    Visit the flutter_samples repository to find integration demo examples.

Dependency Reference

Third-party libraries adapted for OpenHarmony should be imported via Git repository. In addition to the required url field, commonly used parameters are as follows:

  • path: The actual path to the library within the repository; otherwise, pubspec.yaml may not be found.
  • ref (optional): Specifies the version to fetch, which can be a branch name, tag, or commit ID. If omitted, the repository's default branch will be used.

Reference by Branch:

dev_dependencies:
  pigeon:
    git:
      url: https://gitcode.com/openharmony-tpc/flutter_packages.git
      path: packages/pigeon
      ref: pigeon-v21.2.0 # Branch name

Reference by Tag:

dev_dependencies:
  pigeon:
    git:
      url: https://gitcode.com/openharmony-tpc/flutter_packages.git
      path: packages/pigeon
      ref: gitee/pigeon-v11.0.1	# Release tag

Usage Examples

1. Use of tool library pigeon

  1. Introduce the pigeon library and add new configuration to dev_dependencies in pubspec.yaml:

    dependencies:
      pigeon:
        git:
          url: https://gitcode.com/openharmony-tpc/flutter_packages.git
          path: packages/pigeon
          ref: br_pigeon-v26.1.5_ohos
    
  2. Run flutter pub get in the project root directory;

  3. Run flutter pub run pigeon in the project root directory --input <dart communication model file path> --arkts_out <arkts platform method code output file path, example./ohos/entry/src/main/ets/xxx.ets>

The template code for communication between Flutter and the OpenHarmony platform will be generated;

  1. For calling examples, refer to packages/pigeon/example/app/ohos/entry/src/main/ets/plugins/MessagePlugin.ets

2. Use of plug-in library

Take path_provider as an example:

  1. In the referenced project, add new dependencies configuration in pubspec.yaml:

    dependencies:
      path_provider:
        git:
          url: https://gitcode.com/openharmony-tpc/flutter_packages.git
          path: packages/path_provider/path_provider
          ref: br_path_provider-v2.1.5_ohos
    
  2. Run flutter pub get in the project root directory; (ohos/entry/oh-package.json5 will automatically add related plug-in har dependencies)

  3. Call the path_provider related API in the business code, and it will run normally on the OpenHarmony platform.

Example: Add the path_provider library dependency that supports the OpenHarmony platform to a Flutter-compatible OpenHarmony project;

Reference examples: https://gitcode.com/openharmony-tpc/flutter_samples/tree/master/ohos/pictures_provider_demo.

OpenHarmony Compatible Packages

No Original Package Name 3.7 Recommended Version 3.22 Recommended Version 3.27 Recommended Version 3.35 Recommended Version Status
1 pigeon 14.0.0 21.2.0 25.3.2 26.1.5 Compatible
2 file_selector 1.0.1 1.0.3 1.0.3 1.1.0 Compatible
3 image_picker 1.0.4 1.1.2 1.1.2 1.2.1 Compatible
4 animations 2.0.8 2.0.8 2.0.11 2.0.11 Compatible
5 url_launcher 6.1.11 6.3.0 6.3.1 6.3.2 Compatible
6 shared_preferences 2.2.2 2.3.2 2.5.3 2.5.4 Compatible
7 path_provider 2.1.1 2.1.4 2.1.5 2.1.5 Compatible
8 local_auth 2.1.6 2.3.0 2.3.0 3.0.0 Compatible
9 camera 0.10.5+5 0.11.0+2 0.11.1 0.11.3 Compatible
10 video_player 2.7.2 2.9.2 2.10.0 2.10.1 Compatible
11 webview_flutter 4.4.2 4.8.0 4.13.0 4.13.0 Compatible
12 webview_flutter-v4.4.4 4.4.4 - - - Compatible
13 in_app_purchase 3.1.11 3.2.0 3.2.3 3.2.3 Compatible
14 css_colors - - - - -
15 flutter_adaptive_scaffold - - - - -
16 flutter_image - - - - -
17 flutter_lints - - - - -
18 flutter_markdown - - - - -
19 flutter_migrate - - - - -
20 go_router - - - - -
21 go_router_builder - - - - -
22 metrics_center - - - - -
23 multicast_dns - - - - -
24 palette_generator - - - - -
25 pointer_interceptor - - - - -
26 rfw - - - - -
27 standard_message_codec - - - - -
28 two_dimensional_scrollables - - - - -
29 web_benchmarks - - - - -
30 xdg_directories - - - - -
  • Note: A status of - indicates a pure Dart library that works out of the box.

FAQ

1. Run flutter pub get displayed "File name too long" error

Open the Git Bash or cmd.exe(you need to have git as an environment variable) and execute the following command:

  git config --global core.longpaths true

Communication

Introduction

开发者可通过本项目在 Flutter 应用中无缝集成常用插件,最小化业务改动获得完整 OpenHarmony 原生能力支持。项目基于 Flutter 社区官方插件库扩展,新增对 OpenHarmony 平台的兼容适配,提供多个已适配插件及使用示例。【此简介由AI生成】

Customize your domain