此提交包含多项变更: 1. 新增鸿蒙平台支持,完善设备检测与数据库适配 2. 替换旧版分享插件API为SharePlus 3. 批量迁移StateNotifier到Notifier以适配新版Riverpod 4. 修复zip编码判断、图表API参数等bug 5. 更新应用图标、启动页资源与多尺寸适配图标 6. 调整Android最小SDK版本与应用名称 7. 优化日志打印与正则表达式使用 8. 修正编辑器画布样式初始化与配置逻辑 9. 更新依赖与CI插件配置
119 lines
3.4 KiB
Dart
119 lines
3.4 KiB
Dart
// ============================================================
|
|
// 闲言APP — 内容查重状态管理
|
|
// 创建时间: 2026-04-29
|
|
// 更新时间: 2026-04-29
|
|
// 作用: 查重输入/结果/模式状态管理
|
|
// 上次更新: 初始创建
|
|
// ============================================================
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../../core/utils/logger.dart';
|
|
import '../models/check_models.dart';
|
|
import '../services/check_service.dart';
|
|
|
|
class CheckState {
|
|
const CheckState({
|
|
this.isChecking = false,
|
|
this.error,
|
|
this.result,
|
|
this.selectedMode = CheckMode.fuzzy,
|
|
this.selectedSources = const [],
|
|
});
|
|
|
|
final bool isChecking;
|
|
final String? error;
|
|
final CheckResult? result;
|
|
final CheckMode selectedMode;
|
|
final List<String> selectedSources;
|
|
|
|
CheckState copyWith({
|
|
bool? isChecking,
|
|
String? error,
|
|
bool clearError = false,
|
|
CheckResult? result,
|
|
bool clearResult = false,
|
|
CheckMode? selectedMode,
|
|
List<String>? selectedSources,
|
|
}) {
|
|
return CheckState(
|
|
isChecking: isChecking ?? this.isChecking,
|
|
error: clearError ? null : (error ?? this.error),
|
|
result: clearResult ? null : (result ?? this.result),
|
|
selectedMode: selectedMode ?? this.selectedMode,
|
|
selectedSources: selectedSources ?? this.selectedSources,
|
|
);
|
|
}
|
|
}
|
|
|
|
class CheckNotifier extends Notifier<CheckState> {
|
|
@override
|
|
CheckState build() => const CheckState();
|
|
CheckNotifier();
|
|
|
|
Future<void> check({required String text}) async {
|
|
if (text.trim().isEmpty) return;
|
|
state = state.copyWith(
|
|
isChecking: true, clearError: true, clearResult: true);
|
|
|
|
try {
|
|
final CheckResult result;
|
|
switch (state.selectedMode) {
|
|
case CheckMode.exact:
|
|
result = await CheckService.exactCheck(
|
|
text: text,
|
|
sources: state.selectedSources.isNotEmpty
|
|
? state.selectedSources
|
|
: null,
|
|
);
|
|
case CheckMode.fuzzy:
|
|
result = await CheckService.fuzzyCheck(
|
|
text: text,
|
|
sources: state.selectedSources.isNotEmpty
|
|
? state.selectedSources
|
|
: null,
|
|
);
|
|
case CheckMode.similar:
|
|
result = await CheckService.similarCheck(
|
|
text: text,
|
|
sources: state.selectedSources.isNotEmpty
|
|
? state.selectedSources
|
|
: null,
|
|
);
|
|
case CheckMode.report:
|
|
result = await CheckService.reportCheck(
|
|
text: text,
|
|
sources: state.selectedSources.isNotEmpty
|
|
? state.selectedSources
|
|
: null,
|
|
);
|
|
}
|
|
state = state.copyWith(isChecking: false, result: result);
|
|
} catch (e) {
|
|
Log.e('查重失败', e);
|
|
state = state.copyWith(isChecking: false, error: '查重失败');
|
|
}
|
|
}
|
|
|
|
void setMode(CheckMode mode) {
|
|
state = state.copyWith(selectedMode: mode);
|
|
}
|
|
|
|
void toggleSource(String sourceId) {
|
|
final sources = [...state.selectedSources];
|
|
if (sources.contains(sourceId)) {
|
|
sources.remove(sourceId);
|
|
} else {
|
|
sources.add(sourceId);
|
|
}
|
|
state = state.copyWith(selectedSources: sources);
|
|
}
|
|
|
|
void clearResult() {
|
|
state = state.copyWith(clearResult: true, clearError: true);
|
|
}
|
|
}
|
|
|
|
final checkProvider =
|
|
NotifierProvider<CheckNotifier, CheckState>(CheckNotifier.new);
|