Flutter+三方库+鸿蒙 实战:API20+ 智能备忘录开发全流程
欢迎加入开源鸿蒙跨平台社区: https://openharmonycrossplatform.csdn.net一、项目概述本项目是基于 Flutter 跨端框架开发的智能备忘录应用,专为鸿蒙 6.0+(API20+)设备适配。通过集成 4 个鸿蒙化三方库,实现「笔记新增 / 编辑 / 删除」「富文本格式设置」「数据本地持久化」「下拉刷新同步」核心功能,无需为鸿蒙单独编写原生代码,仅通过一套 Da
欢迎加入开源鸿蒙跨平台社区: https://openharmonycrossplatform.csdn.net
一、项目概述
本项目是基于 Flutter 跨端框架开发的智能备忘录应用,专为鸿蒙 6.0+(API20+)设备适配。通过集成 4 个鸿蒙化三方库,实现「笔记新增 / 编辑 / 删除」「富文本格式设置」「数据本地持久化」「下拉刷新同步」核心功能,无需为鸿蒙单独编写原生代码,仅通过一套 Dart 代码即可在鸿蒙设备上稳定运行。
核心技术栈
| 技术 / 工具 | 版本要求 | 作用说明 |
|---|---|---|
| DevEco Studio | 6.0+ | 鸿蒙开发 IDE,提供 Flutter 插件支持 |
| Flutter SDK | 3.27.4-ohos | 社区维护的鸿蒙适配版 Flutter |
| 鸿蒙 SDK | API20+(鸿蒙 6.0+) | 应用运行的系统基础 |
| 三方库 | 鸿蒙适配版 | 实现核心功能(下文详细说明) |
三方库选型(鸿蒙化适配)
| 三方库名称 | 版本 / 来源 | 核心作用 | 适配优势 |
|---|---|---|---|
| shared_preferences | 鸿蒙社区适配版 | 本地数据持久化 | 支持鸿蒙 Preferences API,数据不丢失 |
| flutter_quill | ^7.0.0(适配版) | 富文本编辑 | 支持字体 / 颜色 / 列表设置,鸿蒙 UI 兼容 |
| pull_to_refresh | 鸿蒙社区分支 | 下拉刷新 | 适配鸿蒙触摸事件,无卡顿闪退 |
| path_provider | 鸿蒙适配版 | 文件路径获取 | 兼容鸿蒙文件系统,支持附件存储 |
二、环境搭建(新手必看)
1. 安装 DevEco Studio 6.0+
-
安装时勾选「HarmonyOS SDK API20」,自动下载适配鸿蒙 6.0 + 的系统资源
-
安装 Flutter 插件:
File → Settings → Plugins → 搜索Flutter → 安装官方插件 → 重启IDE
2. 配置 Flutter 鸿蒙 SDK
\# 1. 克隆社区维护的鸿蒙适配版 Flutter SDK(需先安装Git)
git clone -b oh-3.27.4-dev https://gitcode.com/openharmony-tpc/flutter\_flutter.git
\# 2. 配置系统环境变量(Windows示例)
\# 新建 FLUTTER\_HOME 变量,值为克隆后的SDK路径(如:D:\flutter\_flutter)
\# 在 Path 中添加:%FLUTTER\_HOME%\bin、%FLUTTER\_HOME%\bin\cache\dart-sdk\bin
\# 3. 开启鸿蒙支持
flutter config --enable-harmony
\# 4. 验证配置(终端执行)
flutter --version # 需显示 Flutter 3.27.4-ohos 及以上版本
3. 创建鸿蒙模拟器(API20+)
-
打开 DevEco Studio →
Tools → Device Manager -
点击
New Device→ 选择「Phone」→ 挑选鸿蒙 6.0 + 机型(如 Mate 70 Pro) -
点击
Create下载镜像(需联网),创建完成后点击「Start」启动模拟器
三、项目创建与配置
1. 创建 Flutter 鸿蒙项目
-
DevEco Studio →
File → New → New Project -
左侧选择「Flutter」→ 右侧选择「Flutter HarmonyOS Project」
-
填写项目信息:
-
Project Name:
flutter_harmony_memo -
Save Location:非中文无空格路径
-
Flutter SDK Path:选择步骤 2 克隆的鸿蒙适配版 SDK
-
Minimum HarmonyOS SDK:API20(自动匹配鸿蒙 6.0+)
- 点击「Finish」完成创建,等待项目同步完成
2. 配置三方库依赖(pubspec.yaml)
打开项目根目录的 pubspec.yaml,替换 dependencies 节点内容(所有库均为鸿蒙适配版):
environment:
  sdk: '>=3.0.0 .0.0'
  flutter: ">=3.27.0" # 与Flutter SDK版本匹配
dependencies:
  flutter:
  sdk: flutter
  \# 1. 本地数据持久化(鸿蒙适配版)
  shared\_preferences:
  git:
  url: "https://gitcode.com/openharmony-tpc/flutter\_packages.git"
  path: "packages/shared\_preferences/shared\_preferences"
  ref: "br\_shared\_preferences-v2.5.4\_ohos"
  \# 2. 富文本编辑(兼容鸿蒙UI)
  flutter\_quill: ^7.0.0
  \# 富文本依赖的文件路径库(鸿蒙适配版)
  path\_provider:
  git:
  url: "https://gitcode.com/openharmony-tpc/flutter\_packages.git"
  path: "packages/path\_provider/path\_provider"
  ref: "br\_path\_provider-v2.1.5\_ohos"
  \# 3. 下拉刷新(适配鸿蒙触摸事件)
  pull\_to\_refresh:
  git:
  url: "https://gitcode.com/openharmony-tpc/flutter\_packages.git"
  path: "packages/pull\_to\_refresh/pull\_to\_refresh"
  ref: "ohos-adapt"
  \# 4. 日期时间处理(纯Dart库,无需适配)
  intl: ^0.19.0
dev\_dependencies:
  flutter\_test:
  sdk: flutter
  flutter\_lints: ^3.0.0
flutter:
  uses-material-design: true # 启用Material Design组件
3. 安装依赖与同步项目
\# 终端执行(项目根目录)
flutter clean # 清理缓存
flutter pub get # 下载三方库
- 等待依赖安装完成后,点击 DevEco Studio 顶部「Sync」按钮,确保无报错
4. 配置鸿蒙权限(module.json5)
打开 ohos/entry/src/main/module.json5,添加存储权限(用于持久化备忘录数据):
{
  "module": {
  "name": "entry",
  "type": "entry",
  "srcEntry": "./ets/entryability/EntryAbility.ets",
  "description": "\$string:module\_desc",
  "mainElement": "EntryAbility",
  "deviceTypes": \["phone"],
  "deliveryWithInstall": true,
  "installationFree": false,
  "pages": "\$profile:main\_pages",
  "abilities": \[
  {
  "name": "EntryAbility",
  "srcEntry": "./ets/entryability/EntryAbility.ets",
  "description": "\$string:EntryAbility\_desc",
  "icon": "\$media:icon",
  "label": "\$string:EntryAbility\_label",
  "startWindowIcon": "\$media:icon",
  "startWindowBackground": "\$color:start\_window\_background",
  "skills": \[
  {
  "entities": \["entity.system.home"],
  "actions": \["action.system.home"]
  }
  ]
  }
  ],
  // 新增权限配置(API20+要求显式声明)
  "requestPermissions": \[
  {
  "name": "ohos.permission.WRITE\_USER\_STORAGE",
  "reason": "需要存储备忘录数据",
  "usedScene": {
  "abilities": \["EntryAbility"],
  "when": "always"
  }
  },
  {
  "name": "ohos.permission.READ\_USER\_STORAGE",
  "reason": "需要读取备忘录数据",
  "usedScene": {
  "abilities": \["EntryAbility"],
  "when": "always"
  }
  }
  ]
  }
}
四、核心代码实现(分模块讲解)
1. 数据模型封装(lib/models/memo_model.dart)
定义备忘录数据结构,统一数据格式:
import 'package:intl/intl.dart';
/// 备忘录数据模型
class MemoModel {
  final String id; // 唯一标识(避免重复)
  final String content; // 富文本内容(JSON格式存储)
  final String title; // 笔记标题(截取前20字)
  final DateTime createTime; // 创建时间
  final DateTime updateTime; // 更新时间
  bool isStarred; // 是否星标(收藏)
  MemoModel({
  required this.id,
  required this.content,
  required this.title,
  required this.createTime,
  required this.updateTime,
  this.isStarred = false,
  });
  /// 从JSON解析为模型(用于从本地存储读取)
  factory MemoModel.fromJson(Map) {
  return MemoModel(
  id: json\['id'],
  content: json\['content'],
  title: json\['title'],
  createTime: DateTime.parse(json\['createTime']),
  updateTime: DateTime.parse(json\['updateTime']),
  isStarred: json\['isStarred'] ?? false,
  );
  }
  /// 转换为JSON(用于存储到本地)
  Map\<String, dynamic> toJson() {
  return {
  'id': id,
  'content': content,
  'title': title,
  'createTime': createTime.toIso8601String(),
  'updateTime': updateTime.toIso8601String(),
  'isStarred': isStarred,
  };
  }
  /// 格式化时间显示(如:2024-05-20 14:30)
  String get formattedTime {
  return DateFormat('yyyy-MM-dd HH:mm').format(updateTime);
  }
  /// 复制对象(用于修改时不影响原数据)
  MemoModel copyWith({
  String? id,
  String? content,
  String? title,
  DateTime? createTime,
  DateTime? updateTime,
  bool? isStarred,
  }) {
  return MemoModel(
  id: id ?? this.id,
  content: content ?? this.content,
  title: title ?? this.title,
  createTime: createTime ?? this.createTime,
  updateTime: updateTime ?? this.updateTime,
  isStarred: isStarred ?? this.isStarred,
  );
  }
}
2. 本地存储服务(lib/services/storage_service.dart)
基于 shared_preferences 实现数据持久化,封装增删改查方法:
import 'package:shared\_preferences/shared\_preferences.dart';
import '../models/memo\_model.dart';
/// 本地存储服务(单例模式,全局唯一)
class StorageService {
  static StorageService? \_instance;
  late SharedPreferences \_prefs;
  // 私有构造函数,防止外部创建实例
  StorageService.\_();
  /// 获取单例实例
  static FutureInstance() async {
  if (\_instance == null) {
  \_instance = StorageService.\_();
  // 初始化SharedPreferences(鸿蒙适配版已处理底层调用)
  \_instance!.\_prefs = await SharedPreferences.getInstance();
  }
  return \_instance!;
  }
  /// 存储键(用于标识备忘录数据)
  static const String \_memoKey = 'harmony\_flutter\_memos';
  /// 1. 获取所有备忘录
  Future\<MemoModel>> getMemos() async {
  // 从本地读取JSON字符串(鸿蒙存储目录下)
  final String? memoJson = \_prefs.getString(\_memoKey);
  if (memoJson == null || memoJson.isEmpty) {
  return \[]; // 无数据时返回空列表
  }
  // 解析JSON为List>,再转换为MemoModel列表
  final List = await Future(() => 
  (jsonDecode(memoJson) as List>).map((e) => e as Map dynamic>).toList()
  );
  return jsonList.map((json) => MemoModel.fromJson(json)).toList();
  }
  /// 2. 添加/修改备忘录
  FutureMemo(MemoModel memo) async {
  // 先获取现有所有备忘录
  final List\<MemoModel> memos = await getMemos();
  // 移除旧数据(根据id匹配,实现修改功能)
  memos.removeWhere((item) => item.id == memo.id);
  // 添加新数据
  memos.add(memo);
  // 转换为JSON字符串存储
  final String jsonString = jsonEncode(memos.map((e) => e.toJson()).toList());
  return \_prefs.setString(\_memoKey, jsonString);
  }
  /// 3. 删除备忘录
  Future> deleteMemo(String memoId) async {
  final List> memos = await getMemos();
  // 根据id移除对应备忘录
  memos.removeWhere((item) => item.id == memoId);
  // 重新存储修改后的列表
  final String jsonString = jsonEncode(memos.map((e) => e.toJson()).toList());
  return \_prefs.setString(\_memoKey, jsonString);
  }
  /// 4. 清空所有备忘录
  Future\<bool> clearAllMemos() async {
  return \_prefs.remove(\_memoKey);
  }
}
3. 主页面实现(备忘录列表,lib/main.dart)
集成下拉刷新、列表展示、星标功能,使用 pull_to_refresh 实现刷新逻辑:
import 'package:flutter/material.dart';
import 'package:pull\_to\_refresh/pull\_to\_refresh.dart';
import 'models/memo\_model.dart';
import 'services/storage\_service.dart';
import 'pages/edit\_memo\_page.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
  return MaterialApp(
  title: 'Flutter鸿蒙智能备忘录',
  theme: ThemeData(
  primarySwatch: Colors.blue,
  // 适配鸿蒙系统字体样式
  textTheme: const TextTheme(
  bodyLarge: TextStyle(fontSize: 18),
  bodyMedium: TextStyle(fontSize: 16),
  ),
  ),
  home: const MemoListPage(),
  debugShowCheckedModeBanner: false, // 隐藏调试水印
  );
  }
}
class MemoListPage extends StatefulWidget {
  const MemoListPage({super.key});
  @override
  State> createState() => \_MemoListPageState();
}
class \_MemoListPageState extends State\<MemoListPage> {
  late List\<MemoModel> \_memos = \[];
  late StorageService \_storageService;
  final RefreshController \_refreshController = RefreshController(initialRefresh: false);
  /// 初始化:获取存储服务实例 + 加载备忘录数据
  @override
  void initState() {
  super.initState();
  \_initStorageAndLoadMemos();
  }
  /// 初始化存储服务并加载数据
  Future \_initStorageAndLoadMemos() async {
  \_storageService = await StorageService.getInstance();
  await \_loadMemos();
  }
  /// 加载备忘录数据(核心方法)
  Future \_loadMemos() async {
  final List\<MemoModel> loadedMemos = await \_storageService.getMemos();
  // 按更新时间倒序排序(最新的在最前面)
  loadedMemos.sort((a, b) => b.updateTime.compareTo(a.updateTime));
  setState(() {
  \_memos = loadedMemos;
  });
  }
  /// 下拉刷新触发
  Future() async {
  await \_loadMemos(); // 重新加载数据
  \_refreshController.refreshCompleted(); // 结束刷新动画
  }
  /// 跳转到编辑页面(新增/修改)
  void \_navigateToEditPage({MemoModel? memo}) async {
  // 等待编辑页面返回结果
  final MemoModel? result = await Navigator.push(
  context,
  MaterialPageRoute(
  builder: (context) => EditMemoPage(memo: memo),
  ),
  );
  // 如果返回了备忘录数据,说明需要保存
  if (result != null) {
  await \_storageService.saveMemo(result);
  await \_loadMemos(); // 重新加载列表
  }
  }
  /// 删除备忘录
  FuturedeleteMemo(String memoId) async {
  // 显示确认对话框(鸿蒙系统原生样式适配)
  final bool confirm = await showDialog(
  context: context,
  builder: (context) => AlertDialog(
  title: const Text('确认删除'),
  content: const Text('是否删除该备忘录?删除后无法恢复'),
  actions: \[
  TextButton(
  onPressed: () => Navigator.pop(context, false),
  child: const Text('取消'),
  ),
  TextButton(
  onPressed: () => Navigator.pop(context, true),
  child: const Text('删除', style: TextStyle(color: Colors.red)),
  ),
  ],
  ),
  );
  if (confirm) {
  await \_storageService.deleteMemo(memoId);
  await \_loadMemos(); // 重新加载列表
  }
  }
  /// 切换星标状态
  Future> \_toggleStar(MemoModel memo) async {
  final MemoModel updatedMemo = memo.copyWith(
  isStarred: !memo.isStarred,
  updateTime: DateTime.now(), // 更新时间戳
  );
  await \_storageService.saveMemo(updatedMemo);
  await \_loadMemos();
  }
  @override
  Widget build(BuildContext context) {
  return Scaffold(
  appBar: AppBar(
  title: const Text('智能备忘录'),
  centerTitle: true, // 鸿蒙设备标题居中更美观
  actions: \[
  // 清空所有数据按钮
  IconButton(
  icon: const Icon(Icons.delete\_sweep),
  onPressed: \_memos.isEmpty
  ? null // 无数据时禁用
  : () async {
  final bool confirm = await showDialog(
  context: context,
  builder: (context) => AlertDialog(
  title: const Text('确认清空'),
  content: const Text('是否删除所有备忘录?'),
  actions: \[
  TextButton(
  onPressed: () => Navigator.pop(context, false),
  child: const Text('取消'),
  ),
  TextButton(
  onPressed: () => Navigator.pop(context, true),
  child: const Text('确认', style: TextStyle(color: Colors.red)),
  ),
  ],
  ),
  );
  if (confirm) {
  await \_storageService.clearAllMemos();
  await \_loadMemos();
  }
  },
  ),
  ],
  ),
  body: \_buildMemoList(),
  // 新增备忘录按钮(悬浮按钮,鸿蒙系统适配样式)
  floatingActionButton: FloatingActionButton(
  onPressed: () => \_navigateToEditPage(), // 无参数表示新增
  child: const Icon(Icons.add),
  backgroundColor: Colors.blue,
  ),
  );
  }
  /// 构建备忘录列表
  Widget \_buildMemoList() {
  if (\_memos.isEmpty) {
  // 无数据时显示空状态
  return const Center(
  child: Column(
  mainAxisAlignment: MainAxisAlignment.center,
  children: \[
  Icon(Icons.note\_add, size: 60, color: Colors.grey),
  SizedBox(height: 20),
  Text('暂无备忘录,点击右下角添加', style: TextStyle(fontSize: 16, color: Colors.grey)),
  ],
  ),
  );
  }
  // 有数据时显示下拉刷新列表
  return SmartRefresher(
  controller: \_refreshController,
  onRefresh: \_onRefresh,
  header: const WaterDropHeader(
  complete: Icon(Icons.check, color: Colors.blue), // 刷新完成图标
  ),
  child: ListView.builder(
  padding: const EdgeInsets.all(10),
  itemCount: \_memos.length,
  itemBuilder: (context, index) {
  final MemoModel memo = \_memos\[index];
  return Card(
  elevation: 3, // 阴影效果(适配鸿蒙UI)
  margin: const EdgeInsets.symmetric(vertical: 8),
  child: ListTile(
  // 星标图标
  leading: IconButton(
  icon: Icon(
  memo.isStarred ? Icons.star : Icons.star\_border,
  color: memo.isStarred ? Colors.yellow : Colors.grey,
  ),
  onPressed: () => \_toggleStar(memo),
  ),
  // 备忘录标题
  title: Text(
  memo.title,
  maxLines: 1,
  overflow: TextOverflow.ellipsis,
  style: const TextStyle(fontWeight: FontWeight.w500),
  ),
  // 时间和摘要
  subtitle: Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: \[
  const SizedBox(height: 4),
  Text(
  memo.formattedTime,
  style: const TextStyle(fontSize: 12, color: Colors.grey),
  ),
  ],
  ),
  // 点击进入编辑页面
  onTap: () => \_navigateToEditPage(memo: memo),
  // 侧滑删除
  trailing: IconButton(
  icon: const Icon(Icons.delete, color: Colors.red),
  onPressed: () => \_deleteMemo(memo.id),
  ),
  ),
  );
  },
  ),
  );
  }
}
4. 编辑页面实现(富文本编辑,lib/pages/edit_memo_page.dart)
基于 flutter_quill 实现富文本编辑功能,支持字体、颜色、列表等格式:
import 'package:flutter/material.dart';
import 'package:flutter\_quill/flutter\_quill.dart';
import 'package:intl/intl.dart';
import '../models/memo\_model.dart';
import 'dart:convert';
class EditMemoPage extends StatefulWidget {
  final MemoModel? memo; // 可选参数:编辑时传入已有备忘录,新增时为null
  const EditMemoPage({super.key, this.memo});
  @override
  StatePage> createState() => \_EditMemoPageState();
}
class \_EditMemoPageState extends State> {
  late QuillController \_quillController; // 富文本控制器
  late bool \_isEditing; // 是否为编辑模式
  @override
  void initState() {
  super.initState();
  \_isEditing = widget.memo != null;
  // 初始化富文本控制器
  if (\_isEditing) {
  // 编辑模式:从备忘录内容加载富文本数据
  final List> docJson = jsonDecode(widget.memo!.content);
  \_quillController = QuillController(
  document: Document.fromJson(docJson),
  selection: const TextSelection.collapsed(offset: 0),
  );
  } else {
  // 新增模式:创建空文档
  \_quillController = QuillController(
  document: Document(),
  selection: const TextSelection.collapsed(offset: 0),
  );
  }
  }
  /// 提取富文本内容作为标题(前20字)
  String \_extractTitle() {
  final String plainText = \_quillController.document.toPlainText();
  if (plainText.isEmpty) {
  return \_isEditing ? widget.memo!.title : '无标题备忘录';
  }
  return plainText.length > 20
  ? '\${plainText.substring(0, 20)}...'
  : plainText;
  }
  /// 保存备忘录
  void \_saveMemo() {
  // 转换富文本内容为JSON字符串
  final String contentJson = jsonEncode(\_quillController.document.toJson());
  final MemoModel newMemo = MemoModel(
  id: \_isEditing ? widget.memo!.id : DateTime.now().millisecondsSinceEpoch.toString(), // 唯一ID(时间戳)
  content: contentJson,
  title: \_extractTitle(),
  createTime: \_isEditing ? widget.memo!.createTime : DateTime.now(),
  updateTime: DateTime.now(),
  isStarred: \_isEditing ? widget.memo!.isStarred : false,
  );
  // 返回上一页并传递新备忘录数据
  Navigator.pop(context, newMemo);
  }
  @override
  Widget build(BuildContext context) {
  return Scaffold(
  appBar: AppBar(
  title: Text(\_isEditing ? '编辑备忘录' : '新增备忘录'),
  centerTitle: true,
  actions: \[
  // 保存按钮
  TextButton(
  onPressed: \_saveMemo,
  child: const Text('保存', style: TextStyle(color: Colors.white, fontSize: 16)),
  ),
  ],
  ),
  body: Column(
  children: \[
  // 富文本工具栏(字体、颜色、列表等)
  QuillToolbar.basic(
  controller: \_quillController,
  showUnderLineButton: true,
  showBoldButton: true,
  showItalicButton: true,
  showColorButton: true,
  showListCheck: true,
  showListBullet: true,
  showListOrdered: true,
  toolbarIconSize: 24, // 适配鸿蒙设备图标大小
  padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
  ),
  // 富文本编辑区域
  Expanded(
  child: Padding(
  padding: const EdgeInsets.all(16.0),
  child: SingleChildScrollView(
  child: QuillEditor.basic(
  controller: \_quillController,
  readOnly: false,
  padding: EdgeInsets.zero,
  // 适配鸿蒙设备文本样式
  customStyles: DefaultStyles(
  paragraph: DefaultTextBlockStyle(
  const TextStyle(fontSize: 18, height: 1.5),
  const Tuple2(16, 16),
  const Tuple2(0, 0),
  null,
  ),
  ),
  ),
  ),
  ),
  ),
  ],
  ),
  );
  }
}
五、项目运行与测试
1. 运行项目
-
确保鸿蒙模拟器已启动(或连接鸿蒙 6.0 + 真机,开启 USB 调试)
-
终端执行运行命令:
flutter run -d # device\_id可通过flutter devices命令查看
\# 若仅连接一台设备,可直接执行:flutter run
- 等待编译完成,应用将自动安装到鸿蒙设备上
2. 功能测试清单
| 测试项 | 操作步骤 | 预期结果 |
|---|---|---|
| 新增备忘录 | 点击右下角 + 号 → 输入内容 → 点击保存 | 列表新增一条备忘录,数据持久化 |
| 富文本编辑 | 选中文字 → 使用工具栏设置粗体 / 颜色 / 列表 | 文本样式正常生效,保存后不丢失 |
| 星标功能 | 点击列表项左侧星标图标 | 星标状态切换(黄色 / 灰色),数据保存 |
| 下拉刷新 | 列表页面下拉 | 刷新列表,显示最新数据 |
| 编辑备忘录 | 点击列表项 → 修改内容 → 保存 | 原备忘录内容更新,时间戳刷新 |
| 删除备忘录 | 点击列表项右侧删除图标 → 确认 | 备忘录从列表移除,本地数据删除 |
| 清空所有 | 点击顶部清空按钮 → 确认 | 所有备忘录删除,显示空状态 |
| 数据持久化 | 关闭应用 → 重新打开 | 之前的备忘录数据完整保留 |
六、常见问题排查
1. 构建失败:三方库下载失败
-
解决方案:检查网络连接,执行
flutter pub get --verbose查看详细日志,若 Git 仓库访问失败,可替换为国内镜像源 -
替代方案:从 OpenHarmony TPC 社区 手动下载三方库,放置到项目
packages目录下
2. 运行闪退:权限未配置
- 解决方案:检查
module.json5中的requestPermissions配置,确保已添加存储权限,重新编译运行
3. 富文本编辑异常:字体错乱
- 解决方案:在
QuillEditor中明确指定customStyles,统一文本样式,避免鸿蒙系统字体冲突
4. 数据不持久化:存储键错误
- 解决方案:确保
StorageService中的_memoKey唯一,未与其他应用冲突,执行flutter clean后重新运行
更多推荐



所有评论(0)