Flutter3.22适配运行鸿蒙系统问题记录

Flutter3.22适配运行鸿蒙系统问题记录

一:适配条件

开源社区在在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平台已兼容库

适配过程问题记录

(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平台已兼容库

把自己的使用到的三方库查找一遍,如果是纯dart库则不需要替换。涉及到与原生交互的三方库需要替换

以下是自己项目的三方库配置供大家参考

yaml 复制代码
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
相关推荐
Bruce_Liuxiaowei5 小时前
HarmonyOS NEXT~鸿蒙操作系统功耗优化特性深度解析
华为·harmonyos
SuperHeroWu76 小时前
【HarmonyOS 5】鸿蒙中的UIAbility详解(二)
华为·harmonyos·数据传递·uiability·启动模式·生命周期监听·监听设备环境信息
weixin_514949296 小时前
跟着华为去变革 ——读《常变与长青》有感
华为·企业管理·流程it·华为变革·变革管理
OBOO鸥柏商用液晶显示厂家8 小时前
OBOO鸥柏丨2025年鸿蒙生态+国产操作系统触摸屏查询一体机核心股
华为·harmonyos
烈焰晴天11 小时前
HarmonyNext使用request.agent.download实现断点下载
鸿蒙·断点下载·request.agent
实在智能RPA17 小时前
实在Agent成业界首批全面适配鸿蒙、麒麟、统信信创系统的智能体
人工智能·华为·harmonyos·agent智能体·实在agent
码农搬砖_202019 小时前
尝鲜纯血鸿蒙,华为国际版本暂时不支持升级。如mateX6 国际版?为什么不支持?什么时候支持?
华为·harmonyos
Jim-zf19 小时前
Flutter 实现6个验收码输入框
开发语言·javascript·flutter
枫叶丹420 小时前
【HarmonyOS Next之旅】DevEco Studio使用指南(二十八) -> 开发云对象
华为·harmonyos·deveco studio·harmonyos next
lifejump1 天前
HUAWEI交换机配置镜像口验证(eNSP)
网络·华为·ensp·华为ensp·路由交换