refactor: 重构项目目录结构与路径引用
1. 调整工具类、平台相关代码的目录组织,将原有根目录下的工具类迁移到`data/`和`platform/`子目录 2. 统一修复全项目的文件导入路径,匹配新的目录结构 3. 新增Web端平台适配的Stub实现,包括Isolate、path_provider、platform_io等 4. 删除旧的单文件平台适配实现,替换为分平台的目录结构实现 5. 移除旧的iOS Widget入口文件,新增Widget Extension的权限配置 6. 调整部分组件的目录位置,统一widget的分类组织 7. 修复部分硬编码文本和废弃的正则表达式逻辑
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
/// ============================================================
|
||||
/// ============================================================
|
||||
/// 闲言APP — 桌面小部件管理页面
|
||||
/// 创建时间: 2026-05-19
|
||||
/// 更新时间: 2026-05-19
|
||||
/// 更新时间: 2026-05-23
|
||||
/// 作用: 管理桌面小部件的安装、数据推送、主题和平台兼容说明
|
||||
/// 上次更新: 修复Android/鸿蒙端添加小部件无反应,改用requestPinWidget+手动指引
|
||||
/// 上次更新: 修复添加小部件假成功提示,增加失败检测和原生添加弹窗
|
||||
/// ============================================================
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
@@ -13,10 +14,10 @@ import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/theme/app_radius.dart';
|
||||
import '../../../core/utils/platform_helper.dart';
|
||||
import '../../../shared/widgets/glass_container.dart';
|
||||
import '../../../shared/widgets/responsive_layout.dart';
|
||||
import '../../../shared/widgets/app_toast.dart';
|
||||
import '../../../core/utils/platform/platform_helper.dart';
|
||||
import '../../../shared/widgets/containers/glass_container.dart';
|
||||
import '../../../shared/widgets/adaptive/responsive_layout.dart';
|
||||
import '../../../shared/widgets/feedback/app_toast.dart';
|
||||
import '../models/widget_type.dart';
|
||||
import '../providers/widget_provider.dart' as wp;
|
||||
|
||||
@@ -179,24 +180,49 @@ class _WidgetManagementPageState extends ConsumerState<WidgetManagementPage> {
|
||||
};
|
||||
|
||||
void _handleAddWidget(WidgetType type) async {
|
||||
final success = await ref.read(wp.widgetProvider.notifier).requestPinWidget(type);
|
||||
if (!success) {
|
||||
final notifier = ref.read(wp.widgetProvider.notifier);
|
||||
final wasInstalled = ref.read(wp.widgetProvider).installedWidgets.contains(type);
|
||||
|
||||
final pinSuccess = await notifier.requestPinWidget(type);
|
||||
|
||||
if (!pinSuccess) {
|
||||
if (!mounted) return;
|
||||
_showManualAddGuide(type);
|
||||
return;
|
||||
}
|
||||
ref.read(wp.widgetProvider.notifier).addWidget(type);
|
||||
AppToast.showInfo('${type.title} 已添加到桌面');
|
||||
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
|
||||
if (!mounted) return;
|
||||
await notifier.loadInstalledWidgets();
|
||||
|
||||
final nowInstalled = ref.read(wp.widgetProvider).installedWidgets.contains(type);
|
||||
if (nowInstalled && !wasInstalled) {
|
||||
AppToast.showInfo('${type.title} 已添加到桌面');
|
||||
} else if (!nowInstalled) {
|
||||
_showManualAddGuide(type);
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePinWidget(WidgetType type) async {
|
||||
final success = await ref.read(wp.widgetProvider.notifier).requestPinWidget(type);
|
||||
if (!success) {
|
||||
final notifier = ref.read(wp.widgetProvider.notifier);
|
||||
final pinSuccess = await notifier.requestPinWidget(type);
|
||||
|
||||
if (!pinSuccess) {
|
||||
if (!mounted) return;
|
||||
_showManualAddGuide(type);
|
||||
return;
|
||||
}
|
||||
ref.read(wp.widgetProvider.notifier).addWidget(type);
|
||||
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
|
||||
if (!mounted) return;
|
||||
await notifier.loadInstalledWidgets();
|
||||
|
||||
final nowInstalled = ref.read(wp.widgetProvider).installedWidgets.contains(type);
|
||||
if (!nowInstalled) {
|
||||
_showManualAddGuide(type);
|
||||
}
|
||||
}
|
||||
|
||||
void _showManualAddGuide(WidgetType type) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/// ============================================================
|
||||
/// ============================================================
|
||||
/// 闲言APP — 桌面小部件状态管理
|
||||
/// 创建时间: 2026-05-19
|
||||
/// 更新时间: 2026-05-19
|
||||
@@ -10,7 +10,7 @@ import 'dart:ui';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:home_widget/home_widget.dart';
|
||||
import 'package:xianyan/core/utils/platform_utils.dart' as pu;
|
||||
import 'package:xianyan/core/utils/platform/platform_utils.dart' as pu;
|
||||
|
||||
import '../../../core/services/data/home_widget_service.dart';
|
||||
import '../../../core/utils/logger.dart';
|
||||
@@ -101,6 +101,7 @@ class WidgetNotifier extends Notifier<WidgetState> {
|
||||
if (pu.isOhos) {
|
||||
try {
|
||||
const dynamic requestPin = HomeWidget.requestPinWidget;
|
||||
// ignore: avoid_dynamic_calls
|
||||
await requestPin(
|
||||
qualifiedAndroidName: type.qualifiedAndroidName,
|
||||
androidName: type.androidProviderName,
|
||||
|
||||
Reference in New Issue
Block a user