1作者: flfljh7 个月前
# 更新 Flutter 插件项目结构 # HarmonyOS 下一步 ## 更新摘要 * 将 Flutter 插件的 `ohos` 目录中的 HarmonyOS 项目结构替换为模块结构 * 将所有引用的 HAR 文件整合到 `ohos/har` 下 * 更新后移除 OHOS 插件中过时的模块目录 ## 更新步骤 以 flutter\_flutter 中的 [integration\_test](https://gitee.com/openharmony-sig/flutter_flutter) 为例进行演示: ### 1. 将 integration\_test/ohos 从项目格式重构为模块格式 ```sh cd flutter_flutter/packages/integration_test mv ohos/ohos ./ohos2 # 备份原始结构 rm -rf ohos # 移除旧结构 mv ohos2 ohos # 重命名为标准模块格式 cd example flutter pub get # 刷新依赖 flutter build hap --debug # 验证构建 ``` > *注意*:在此阶段运行 `flutter run` 将会失败,直到配置更新完成。 ### 2. 配置更新 #### 2.1 更新 integration\_test/ohos/oh-package.json5 *之前*: ```json { "name": "ohos", ... } ``` *之后*(匹配 pubspec.yaml 中的插件名称): ```json { "name": "integration_test", "license": "Apache-2.0", "dependencies": { "@ohos/flutter_ohos": "file:har/flutter.har" } } ``` #### 2.2 更新 integration\_test/ohos/src/main/module.json5 *之前*: ```json { "module": { "name": "ohos", ... } } ``` *之后*: ```json { "module": { "name": "integration_test", ... } } ``` #### 2.3 更新 integration\_test/ohos/hvigorfile.ts *之前*: ```typescript import { appTasks } from '@ohos/hvigor-ohos-plugin'; export default { system: appTasks, plugins:[] } ``` *之后*: ```typescript export { harTasks } from '@ohos/hvigor-ohos-plugin'; ``` ## 验证步骤 1. 在 DevEco Studio 中打开 `integration_test/example` 并配置签名 2. 运行示例: ```sh cd integration_test/example flutter run -d $DEVICE --debug ``` ### 关键 HAR 引用配置 HAR 文件现在位于 `ohos/har` #### 更新 example/ohos/oh-package.json5 ```json { "dependencies": { "@ohos/flutter_ohos": "file:./har/flutter.har" }, "overrides": { "@ohos/flutter_ohos": "file:./har/flutter.har" } } ``` #### 更新 example/ohos/entry/oh-package.json5 *之前*: ```json { "dependencies": { "@ohos/integration_test": "file:./har/integration_test.har" } } ``` *之后*: ```json { "dependencies": { "integration_test": "file:../har/integration_test.har" } } ``` ## 常见问题排查 ### 1. ENOENT: 没有此类文件或目录 *错误*: ```log hvigor ERROR: ENOENT: no such file or directory, stat 'xxx/flutter_flutter/packages/integration_test/ohos/build/default/cache/default/default@packageHar/ohos/oh_modules/@ohos/flutter_ohos' ``` *解决方案*: 手动删除错误消息中提到的路径。 ### 2. 不允许操作(符号链接错误) *错误*: ```log hvigor ERROR: ENOENT: operation not permitted, symlink 'xxx/webview_flutter_ohos/ohos/webview_flutter/oh_modules/.ohpm/@ohos+flutter_ohos@file+libs+flutter.har/oh_modules/@ohos/flutter_ohos' -> 'xxx/webview_flutter_ohos/ohos/build/default/cache/default/default@PackageHar/webview_flutter/oh_modules/@ohos/flutter_ohos' ``` *解决方案*: 从之前的结构中移除旧目录: ```sh rm -rf flutter_packages/packages/webview_flutter_ohos/ohos/webview_flutter rm -rf flutter_packages/packages/path_provider_ohos/ohos/path_provider rm -rf flutter_packages/packages/file_selector_ohos/ohos/FileSelector ```
1作者: flfljh7 个月前
# HarmonyOS 开发基础 ## 数据存储 HarmonyOS 应用提供多种数据存储选项: - *Preferences*:用于存储简单数据的轻量级键值对存储 - *SQLite*:用于存储结构化数据的关系型数据库 - *文件存储*:直接访问文件系统,用于自定义数据存储 ## 数组 数组是由索引访问的有序数据集合: ```javascript let numbers = [1, 2, 3, 4, 5]; console.log(numbers[0]); // 输出 1 ``` ## 函数 ### 普通函数 封装可重用的代码块: ```javascript function greet(name) { return "Hello, " + name; } console.log(greet("Alice")); // 输出 "Hello, Alice" ``` ### 箭头函数 简洁的函数语法: ```javascript const greet = (name) => "Hello, " + name; console.log(greet("Bob")); // 输出 "Hello, Bob" ``` ## 接口 定义对象结构契约: ```typescript interface Person { name: string; age: number; greet(): string; } class Employee implements Person { name: string; age: number; constructor(name: string, age: number) { this.name = name; this.age = age; } greet(): string { return "Hello, I am " + this.name; } } ``` ## 对象和方法 属性和方法的集合: ```javascript let person = { name: "Charlie", age: 30, greet: function() { return "Hello, " + this.name; } }; console.log(person.greet()); // 输出 "Hello, Charlie" ``` ## 联合类型 可以为多种类型之一的值: ```typescript let age: number | string; age = 25; // 有效 age = "twenty-five"; // 也有效 ``` ## 枚举 命名的常量集合: ```typescript enum Direction { Up, Down, Left, Right } let direction: Direction = Direction.Up; // 使用枚举值 ``` ------ ## UI 开发概念和布局 ### 组件属性和方法 - *属性*:配置外观和行为 - *方法*:执行特定于组件的操作 ### 文本样式 - *文本颜色*:通过 `text-color` 属性设置 - *文本溢出*:使用 `text-overflow` 控制(例如,`ellipsis` 显示截断点) ### 图像组件 ```html <image src="path/to/image.png" width="100" height="100"></image> ``` ### 输入框 ```html <input type="text" placeholder="Enter text here"></input> ``` ### SVG 图标 直接嵌入或引用 SVG 文件: ```html <svg width="100" height="100"> <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /> </svg> ``` ### 布局元素 组织 UI 组件的定位和大小调整 #### 外边距 ```css .container { margin: 10px; /* 统一外边距 */ margin: 5px 10px; /* 垂直 | 水平 */ margin: 5px 10px 15px; /* 顶部 | 水平 | 底部 */ margin: 5px 10px 15px 20px; /* 顶部 | 右侧 | 底部 | 左侧 */ } ``` #### 边框 ```css .box { border: 1px solid black; /* 宽度 | 样式 | 颜色 */ border-radius: 10px; /* 圆角 */ } ``` #### 自定义形状 ```css .special-shape { border-radius: 20px 10px 30px 5px; /* 自定义圆角 */ } ``` ### 背景 ```css .background { background-color: #f0f0f0; /* 纯色 */ background-image: url('path/to/image.png'); /* 背景图片 */ background-position: center; /* 图片定位 */ background-size: cover; /* 图片大小 */ background-repeat: no-repeat; /* 阻止平铺 */ } ``` ### 线性布局对齐 ```css .linear-layout { display: flex; justify-content: center; /* 主轴对齐 */ align-items: center; /* 交叉轴对齐 */ flex-direction: row; /* 布局方向(行/列) */ } ```
1作者: Joshua_Hart7 个月前
13 岁的作家 Joshua Hart 推出了他的官方作家网站:https://joshuahartauthor.com。他创作了《Glow》和《Benny's Blunders》。 该网站展示了他的书籍、项目更新和联系方式。这两本书都通过全球主要零售商发售,该网站也为读者和出版商提供了一个中心平台,方便他们了解更多关于他的作品。
2作者: instagib7 个月前
我注意到我的 iCloud 云盘无法同步。我修复了这个问题,但一两周后又发生了。我决定写一篇博文,记录下解决这个问题的步骤,方便自己或其他人参考,因为我在网上找到的所有方法都无效,而且浪费了我很多时间。