api实现

This commit is contained in:
Developer
2026-04-09 08:54:36 +08:00
parent 2eaf317705
commit 8d27c67d3a
319 changed files with 70169 additions and 4677 deletions

View File

@@ -99,25 +99,7 @@ lib/
| `animations` | git | 页面过渡动画 | AnimationService |
| `flutter_screenutil` | 本地 v5.9.3 | 屏幕适配 | 全局使用(支持鸿蒙) |
## 尚未使用的依赖库
| 库名 | 版本 | 用途 | 建议使用场景 |
|------|------|------|--------------|
| `pigeon` | git | Flutter 与原生平台通信 | 需要调用原生 API 时使用 |
| `orientation` | git | 屏幕方向控制 | 已改用 Flutter 原生 SystemChrome |
| `platform_info` | ^5.0.0 | 平台识别 | 已改用 dart:io 的 Platform |
## 建议添加的基础库
| 库名 | 用途 | 优先级 |
|------|------|--------|
| `image_picker` | 图片选择、拍照 | 高 |
| `url_launcher` | 打开 URL、拨打电话 | 高 |
| `path_provider` | 文件路径获取 | 中 |
| `camera` | 相机访问 | 中 |
| `geolocator` | 地理定位 | 中 |
| `fl_chart` | 图表库 | 低 |
| `sqflite` | SQLite 数据库 | 低 |
## 核心服务说明
@@ -180,69 +162,7 @@ await orientation.lockPortrait();
await orientation.unlockOrientation();
```
### 5. NotificationService通知服务
**功能:**
- 本地通知管理
- 定时通知
- 进度通知
- 大文本通知
- 图片通知
- 通知权限请求
**使用示例:**
```dart
final notification = AppService.instance.notification;
// 请求权限
await notification.requestPermission();
// 显示普通通知
await notification.showNotification(
id: 1,
title: '标题',
body: '内容',
);
// 显示定时通知
await notification.scheduleNotification(
id: 2,
title: '提醒',
body: '该吃饭了!',
scheduledDate: DateTime.now().add(Duration(hours: 1)),
);
// 取消通知
await notification.cancelNotification(1);
```
### 6. AppInfoService应用信息服务
**功能:**
- 获取应用名称
- 获取包名
- 获取版本号
- 获取构建号
- 版本比较
- 更新检测
**使用示例:**
```dart
final appInfo = AppService.instance.appInfo;
// 获取版本信息
print('版本: ${appInfo.version}');
print('构建号: ${appInfo.buildNumber}');
print('完整版本: ${appInfo.fullVersion}');
// 检查是否需要更新
if (appInfo.needsUpdate('2.0.0')) {
print('需要更新应用');
}
// 获取应用信息摘要
print(appInfo.appInfoString);
```
### 7. ToastService消息提示服务
@@ -264,75 +184,6 @@ print(appInfo.appInfoString);
- `ToastStyle.default_` - 默认样式Cupertino 风格)
- `ToastStyle.hybrid` - 混合样式(推荐)
**使用示例:**
```dart
final toast = AppService.instance.toast;
// 设置显示样式
toast.setStyle(ToastStyle.hybrid);
// 显示信息消息
await toast.info('这是一条信息');
// 显示成功消息(积极)
await toast.success('操作成功!');
// 显示警告消息
await toast.warning('请注意!');
// 显示错误消息(消极)
await toast.error('操作失败!');
// 自定义显示
await toast.show(
'自定义消息',
type: MessageType.info,
style: ToastStyle.getx,
duration: Duration(seconds: 3),
);
// 取消所有消息
toast.cancelAll();
```
### 8. PermissionService权限管理服务
**功能:**
- 支持 15 种常见权限类型(相机、麦克风、相册、位置等)
- 跨平台权限适配iOS、Android、HarmonyOS、Web、Windows、macOS、Linux
- 权限状态记录和查询功能
- 批量权限检查和请求功能
**使用示例:**
```dart
final permission = AppService.instance.permission;
// 检查单个权限
final status = await permission.checkPermission(PermissionType.camera);
if (status.isGranted) {
// 权限已授予
}
// 请求单个权限
final result = await permission.requestPermission(PermissionType.camera);
if (result.isGranted) {
// 权限已授予
}
// 批量检查权限
final permissions = [
PermissionType.camera,
PermissionType.microphone,
PermissionType.photos,
];
final statuses = await permission.checkPermissions(permissions);
// 批量请求权限
final results = await permission.requestPermissions(permissions);
// 获取所有权限状态
final allStatuses = permission.getAllPermissionStatuses();
```
### 9. AnimationService动画管理服务
@@ -637,35 +488,6 @@ count.value++;
Obx(() => Text('${count.value}'))
```
### 7. 路由管理
使用 GetX 进行路由管理:
```dart
// 跳转到新页面
Get.to(const NewPage());
// 返回上一页
Get.back();
// 替换当前页面
Get.off(const NewPage());
// 清空栈并跳转
Get.offAll(const HomePage());
```
### 8. 依赖注入
使用 GetX 进行依赖注入:
```dart
// 注册服务
Get.put(ThemeService());
// 获取服务
final theme = Get.find<ThemeService>();
```
## 开发规范