Flutter3.22适配运行鸿蒙系统问题记录
一:适配条件
开源社区在在4月上旬发布了flutter 3.22版本的鸿蒙分支,之前的分支过于老旧,因此可以尝试把自己的项目适配运行
鸿蒙flutter分支地址:
https://gitcode.com/openharmony-sig/flutter_flutter/tree/3.22.0-ohos
已适配三方库地址:
适配过程问题记录
(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)三方插件寻找替换
已适配三方库地址:
把自己的使用到的三方库查找一遍,如果是纯dart库则不需要替换。涉及到与原生交互的三方库需要替换
以下是自己项目的三方库配置供大家参考
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
# get
get:
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"
# toast
fluttertoast:
git:
url: "https://gitcode.com/openharmony-sig/flutter_fluttertoast.git"
# 应用安装管理
install_plugin:
git:
url: "https://gitcode.com/openharmony-sig/fluttertpc_install_plugin.git"
# webview
flutter_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"
# webview
webview_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.0
cookie_jar: ^4.0.8
dio_cookie_manager: ^3.1.1
# 网络图片缓存
cached_network_image: ^3.3.1
photo_view: ^0.15.0
flutter_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
# SVG
flutter_svg: ^2.0.9
#banner图
card_swiper: ^3.0.0
#侧滑删除
flutter_slidable: ^3.0.0
#动画效果
lottie: ^3.1.0
#可定位的listview
scrollable_positioned_list: ^0.3.8
#rsa加密
encrypt: ^5.0.3
#虚线边框
dotted_border: ^2.1.0
# ios 图标库
cupertino_icons: ^1.0.2
# loaing
flutter_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.git
path: packages/path_provider/path_provider
path_provider_ohos:
git:
url: https://gitee.com/openharmony-sig/flutter_packages.git
path: packages/path_provider/path_provider_ohos