Flutter 鸿蒙化实战:flutter_custom_cursor 适配 OpenHarmony,定制光标随心换
·
Flutter 鸿蒙化实战:flutter_custom_cursor 适配 OpenHarmony
前言
随着鸿蒙生态的快速发展,越来越多的 Flutter 应用需要适配 OpenHarmony 平台。但生态早期,大量常用三方库只有 Android / iOS 实现,鸿蒙侧只能自己造轮子。
为了解决这个问题,CPF-Flutter 社区对一批高频使用的 Flutter 三方库做了 OpenHarmony 平台适配,统一托管在 GitCode 的 CPF-Flutter 组织 下,全部通过 TAG 版本隔离、配套门禁编译验证,开箱即用。
本篇是系列文章之一,主角是 flutter_custom_cursor —— 自定义鼠标/触摸光标的插件。
flutter_custom_cursor 是什么
flutter_custom_cursor(原库 0.0.4)允许你为 Flutter 应用自定义光标样式:
- 创建会话:
createSession开启一个光标会话; - 定义光标:通过
name(光标名)、buffer(图片数据)、width/height(尺寸)、hotX/hotY(热点坐标)定制光标外观; - 调试:
debugDescription输出会话描述。
适配情况
| Flutter 框架版本 | TAG 名称 | 分支名 |
|---|---|---|
| 3.7 | 0.0.4-ohos-1.0.0 | master |
| 3.22 | 0.0.4-ohos-1.0.0 | master |
| 3.35 | 0.0.4-ohos-1.0.0 | master |
快速接入
在 pubspec.yaml 中添加 git 依赖:
dependencies:
flutter_custom_cursor:
git:
url: https://gitcode.com/CPF-Flutter/fluttertpc_flutter_custom_cursor.git
# 按你的 Flutter 框架版本,从上方映射表选择对应 TAG
ref: 0.0.4-ohos-1.0.0
执行:
flutter pub get
使用示例
import 'package:flutter_custom_cursor/flutter_custom_cursor.dart';
// 开启光标会话
final session = await CustomCursor().createSession(
name: 'custom',
buffer: imageBytes, // 光标图片字节
width: 32,
height: 32,
hotX: 16,
hotY: 16,
);
// 使用会话
// ......
API 支持一览
| API | 说明 | ohos 支持 |
|---|---|---|
| createSession | 创建光标会话 | yes |
| name | 光标名称 | yes |
| buffer | 光标图片数据 | yes |
| width / height | 光标尺寸 | yes |
| hotX / hotY | 光标热点坐标 | yes |
| debugDescription | 会话调试描述 | yes |
[!TIP] ohos Support 为 yes 表示鸿蒙平台支持该能力,使用方式与 iOS / Android 保持一致。
仓库地址
- OpenHarmony 适配仓库:https://gitcode.com/CPF-Flutter/fluttertpc_flutter_custom_cursor
- 使用问题反馈:请到 CPF-Flutter 社区 Issues 提交问题(社区统一收集跟进);本仓库 Issues 区亦可。
系列预告
截至目前,CPF-Flutter 社区已完成 250+ 个 Flutter 三方库的 OpenHarmony 平台适配,覆盖权限管理、UI 组件、设备信息、位置服务、媒体处理、网络、支付等多个领域,完整的适配清单(含每个库的版本映射表)见:
- 适配总览文档:https://gitcode.com/CPF-Flutter/docs/blob/main/ThirdpartyLibrarites.md
- 仓库组织:https://gitcode.com/CPF-Flutter
本系列后续会陆续挑选高频库展开讲解,比如扫码识别(flutter_barcode_scanner)、录音(record_mp3)、全局异常捕获(catcher)等。
如果你的 Flutter 应用正在计划适配鸿蒙,欢迎关注 CPF-Flutter 组织,也欢迎参与共建。
更多推荐

所有评论(0)