Flutter3.22适配运行鸿蒙系统问题记录
Flutter3.22适配运行鸿蒙系统问题记录
- 一:适配条件
- 适配过程问题记录
- (1)环境配置问题
- (2)Concurrent modification during iteration: Instance(length:2) of'_GrowableList 报错
- (3)三方插件寻找替换
一:适配条件
开源社区在在4月上旬发布了flutter 3.22版本的鸿蒙分支,之前的分支过于老旧,因此可以尝试把自己的项目适配运行
鸿蒙flutter分支地址:
https://gitcode.com/openharmony-sig/flutter_flutter/tree/3.22.0-ohos
已适配三方库地址:
https://gitcode.com/openharmony-sig/flutter_packages#openharmony%E5%B9%B3%E5%8F%B0%E5%B7%B2%E5%85%BC%E5%AE%B9%E5%BA%93
适配过程问题记录
(1)环境配置问题
按照文档配置环境后运行flutter doctor报ohsm sdk找不到,如果按报错去配置环境安装鸿蒙包管理器会很麻烦
直接运行
flutter config --ohos-sdk /Users/vence/Library/OpenHarmony/Sdk(这个地址是自己鸿蒙SDK的安装地址)
如果没有下载sdk在DecEco中自己配置一下
(2)Concurrent modification during iteration: Instance(length:2) of’_GrowableList 报错
此问题查阅资料后为flutter3.22分支上的问题,存在编译问题
解决方案:https://github.com/flutter/flutter/issues/148611
项目全局注释掉MaterialState相关的代码后编译通过。
(3)三方插件寻找替换
已适配三方库地址:
https://gitcode.com/openharmony-sig/flutter_packages#openharmony%E5%B9%B3%E5%8F%B0%E5%B7%B2%E5%85%BC%E5%AE%B9%E5%BA%93
把自己的使用到的三方库查找一遍,如果是纯dart库则不需要替换。涉及到与原生交互的三方库需要替换
以下是自己项目的三方库配置供大家参考
dependencies:flutter:sdk: flutterflutter_localizations:sdk: flutter# getget:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_get.git"# 权限关系permission_handler:git:url: "https://gitcode.com/openharmony-sig/flutter_permission_handler.git"path: "permission_handler"# 二维码扫描mobile_scanner:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_mobile_scanner.git"# # 二维码识别recognition_qrcode:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_recognition_qrcode.git"# 逆定理编码geolocator:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_geolocator.git"path: "geolocator"# 地理编码geocoding:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_geocoding.git"path: "geocoding"# 键盘状态管理flutter_keyboard_visibility:git:url: "https://gitcode.com/openharmony-sig/flutter_keyboard_visibility.git"path: "flutter_keyboard_visibility"# 键盘状态管理keyboard_actions:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_keyboard_actions.git"# 分享share_extend:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_share_extend.git"# toastfluttertoast:git:url: "https://gitcode.com/openharmony-sig/flutter_fluttertoast.git"# 应用安装管理install_plugin:git:url: "https://gitcode.com/openharmony-sig/fluttertpc_install_plugin.git"# webviewflutter_inappwebview:git:url: "https://gitcode.com/openharmony-sig/flutter_inappwebview.git"path: "flutter_inappwebview"# sp存储shared_preferences:git:url: "https://gitcode.com/openharmony-sig/flutter_packages.git"path: "packages/shared_preferences/shared_preferences"# webviewwebview_flutter:git:url: "https://gitcode.com/openharmony-sig/flutter_packages.git"path: "packages/webview_flutter/webview_flutter"# 图片选择image_picker:git:url: "https://gitcode.com/openharmony-sig/flutter_packages.git"path: "packages/image_picker/image_picker"# url管理url_launcher:git:url: "https://gitcode.com/openharmony-sig/flutter_packages.git"path: "packages/url_launcher/url_launcher"# 设备信息获取device_info_plus:git:url: "https://gitcode.com/openharmony-sig/flutter_plus_plugins.git"path: "packages/device_info_plus/device_info_plus"# 文件路径管理path_provider:git:url: "https://gitee.com/openharmony-sig/flutter_packages.git"path: "packages/path_provider/path_provider"# flutter 无需适配的库# 日期格式intl: ^0.19.0# 网络请求dio: ^5.7.0cookie_jar: ^4.0.8dio_cookie_manager: ^3.1.1# 网络图片缓存cached_network_image: ^3.3.1photo_view: ^0.15.0flutter_cache_manager: ^3.1.0# 瀑布流flutter_staggered_grid_view: ^0.7.0# 日志输出插件logger: ^2.0.2+1# 骨架屏skeletonizer: ^1.1.0# 通知event_bus: ^2.0.0# 验证码输入框pin_code_fields: ^8.0.1# 文字轮播marquee: ^2.2.3# SVGflutter_svg: ^2.0.9#banner图card_swiper: ^3.0.0#侧滑删除flutter_slidable: ^3.0.0#动画效果lottie: ^3.1.0#可定位的listviewscrollable_positioned_list: ^0.3.8#rsa加密encrypt: ^5.0.3#虚线边框dotted_border: ^2.1.0# ios 图标库cupertino_icons: ^1.0.2# loaingflutter_easyloading: ^3.0.0# 上拉刷新/下拉加载pull_to_refresh_plus: ^2.0.3# 页面适配flutter_screenutil: ^5.9.0# 图片压缩 2.4版本已经支持鸿蒙flutter_image_compress: ^2.4.0# 这里是为了解决 path_provider 与 cached_network_image 库依赖冲突问题 https://leetcode.cn/discuss/post/3264240/hong-meng-fluttersheng-cheng-hapbao-bian-7utn/
dependency_overrides:path_provider:git:url: https://gitee.com/openharmony-sig/flutter_packages.gitpath: packages/path_provider/path_providerpath_provider_ohos:git:url: https://gitee.com/openharmony-sig/flutter_packages.gitpath: packages/path_provider/path_provider_ohos