Files
xianyan/lib/editor/providers/mini_editor_provider.dart
Developer 7564e8893d chore: 完成多平台适配与代码优化
此提交包含多项变更:
1. 新增鸿蒙平台支持,完善设备检测与数据库适配
2. 替换旧版分享插件API为SharePlus
3. 批量迁移StateNotifier到Notifier以适配新版Riverpod
4. 修复zip编码判断、图表API参数等bug
5. 更新应用图标、启动页资源与多尺寸适配图标
6. 调整Android最小SDK版本与应用名称
7. 优化日志打印与正则表达式使用
8. 修正编辑器画布样式初始化与配置逻辑
9. 更新依赖与CI插件配置
2026-05-17 07:17:07 +08:00

131 lines
3.7 KiB
Dart

// ============================================================
// 闲言APP — 迷你编辑器状态管理
// 创建时间: 2026-04-20
// 更新时间: 2026-04-20
// 作用: 迷你版编辑器极简状态 — 仅文字+背景+导出
// 上次更新: 初始创建
// ============================================================
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:xianyan/core/theme/app_colors.dart';
import 'package:xianyan/editor/models/editor_models.dart';
// ============================================================
// 迷你编辑器状态
// ============================================================
/// 迷你编辑器状态 — 极简6项
class MiniEditorState {
const MiniEditorState({
required this.text,
this.fontSize = 28.0,
this.textColor = Colors.white,
this.background = const BackgroundLayer(
type: BackgroundType.gradient,
gradientColors: [LightColors.primary, LightColors.primaryDark],
gradientBegin: Alignment.topLeft,
gradientEnd: Alignment.bottomRight,
),
this.isExporting = false,
});
final String text;
final double fontSize;
final Color textColor;
final BackgroundLayer background;
final bool isExporting;
/// 生成标准画布模型 (用于导出)
QuoteCanvasModel toCanvas() {
return QuoteCanvasModel(
background: background,
textLayers: [
TextLayer(
id: 'mini_title',
text: text,
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: textColor,
),
],
);
}
MiniEditorState copyWith({
String? text,
double? fontSize,
Color? textColor,
BackgroundLayer? background,
bool? isExporting,
}) {
return MiniEditorState(
text: text ?? this.text,
fontSize: fontSize ?? this.fontSize,
textColor: textColor ?? this.textColor,
background: background ?? this.background,
isExporting: isExporting ?? this.isExporting,
);
}
}
// ============================================================
// 迷你编辑器 StateNotifier
// ============================================================
/// 迷你编辑器状态控制器 — 无撤销/重做,无多图层
class MiniEditorNotifier extends Notifier<MiniEditorState> {
@override
MiniEditorState build() => const MiniEditorState(text: '在此输入文字');
void updateText(String text) {
state = state.copyWith(text: text);
}
void updateFontSize(double size) {
state = state.copyWith(fontSize: size);
}
void updateTextColor(Color color) {
state = state.copyWith(textColor: color);
}
void updateBackground(BackgroundLayer bg) {
state = state.copyWith(background: bg);
}
void setExporting(bool exporting) {
state = state.copyWith(isExporting: exporting);
}
}
// ============================================================
// Provider
// ============================================================
/// 迷你编辑器 Provider — family 支持不同初始值
final miniEditorProvider =
NotifierProvider<MiniEditorNotifier, MiniEditorState>(
MiniEditorNotifier.new,
);
/// 迷你编辑器参数
class MiniEditorParams {
const MiniEditorParams({this.initialText, this.initialBackground});
final String? initialText;
final BackgroundLayer? initialBackground;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is MiniEditorParams &&
runtimeType == other.runtimeType &&
initialText == other.initialText &&
initialBackground == other.initialBackground;
@override
int get hashCode => Object.hash(initialText, initialBackground);
}