12小时,10次提交,完成纯血鸿蒙适配

229 阅读1分钟

image.png

以上为适配记录。

使用Flutter开发的,所以主要的困难点就是找适配的库,但是好在[极简记物]大部分的逻辑都不涉及原生,即使涉及到原生也是使用的比较通用的库。所以适配难度上不是很大。鸿蒙版本提供的适配库见:gitcode.com/openharmony…

第一个难点就是原来使用的flutter版本是最新的版本,鸿蒙版本是基于3.22?版本。所以有一些降级后的报错信息,基本是集中于

style: textTheme.titleMedium!.copyWith(
    color: contentColor.withValues(alpha: 0.85),
    overflow: TextOverflow.ellipsis),
    -----------以上为高版本,以下为低版本---------
    style: textTheme.titleMedium!.copyWith(
    color: contentColor.withOpacity( 0.85),
    overflow: TextOverflow.ellipsis),

以及

onPopInvokedWithResult: (didPop, result) async {
  // doSomething
},
-----------以上为高版本,以下为低版本---------
onPopInvoked: (didPop) async {
  // doSomething
},

还有一个比较印象深刻的就是cached_network_image的适配,相信使用flutter的大部分用户都使用过这个缓存库。之前一直依赖报错,我这里就直接给结果了:

dependency_overrides:
  path_provider:
    git:
      url: "https://gitcode.com/openharmony-sig/flutter_packages.git"
      path: "packages/path_provider/path_provider"

强制使用鸿蒙版本的path_provider即可解决依赖报错问题。

还有个点就是图片展示时会有个黑色的填充。通过以下代码即可修复,原理未知

// 鸿蒙平台特殊处理
if (Platform.isOhos) {
  return Container(
    width: widget.size,
    height: widget.size,
    color: Colors.transparent,
    child: CachedNetworkImage(
      imageUrl: url ?? "",
      progressIndicatorBuilder: (context, url, downloadProgress) =>
          CircularProgressIndicator(value: downloadProgress.progress),
      errorWidget: (context, url, error) => Icon(Icons.broken_image),
      width: widget.size,
      height: widget.size,
      fit: widget.fit,
      cacheKey: url,
    ),
  );
}

应用名[极简记物],多个应用市场已上架。纯血鸿蒙版本内测邀请链接(周末还在审核,可能要下周才能正常使用):点这里

image.png