Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 39 additions & 27 deletions jive-flutter/lib/screens/theme_management_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -408,31 +408,31 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
case 'eye_comfort':
await ThemeService().applyEyeComfortTheme();
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
const SnackBar(content: Text('已应用护眼主题')),
);
}
break;
case 'apply_eye_bluegrey':
await ThemeService().applyPresetTheme('preset_eye_bluegrey');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
const SnackBar(content: Text('已应用护眼·蓝灰')),
);
}
break;
case 'apply_eye_green':
await ThemeService().applyPresetTheme('preset_eye_green');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
const SnackBar(content: Text('已应用护眼·青绿')),
);
}
break;
case 'apply_eye_dark':
await ThemeService().applyPresetTheme('preset_eye_dark');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
const SnackBar(content: Text('已应用护眼·夜间')),
);
}
Expand Down Expand Up @@ -463,7 +463,7 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
if (!mounted) return;

if (result != null) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('主题"${result.name}"创建成功'),
backgroundColor: Colors.green,
Expand All @@ -481,7 +481,7 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
if (!mounted) return;

if (result != null) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('主题"${result.name}"已更新'),
backgroundColor: Colors.green,
Expand All @@ -498,6 +498,7 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
}

Future<void> _copyTheme(models.CustomThemeData theme) async {
final messenger = ScaffoldMessenger.of(context);
try {
final newTheme = await _themeService.createCustomTheme(
name: '${theme.name} (副本)',
Expand All @@ -507,14 +508,14 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
);
if (!mounted) return;

ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('主题"${newTheme.name}"创建成功'),
backgroundColor: Colors.green,
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('复制失败: $e'),
backgroundColor: Colors.red,
Expand All @@ -524,17 +525,18 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
}

Future<void> _exportTheme(models.CustomThemeData theme) async {
final messenger = ScaffoldMessenger.of(context);
try {
await _themeService.copyThemeToClipboard(theme.id);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
if (!mounted) return;
messenger.showSnackBar(
const SnackBar(
content: Text('主题已复制到剪贴板'),
backgroundColor: Colors.green,
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('导出失败: $e'),
backgroundColor: Colors.red,
Expand All @@ -544,18 +546,22 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
}

Future<void> _deleteTheme(models.CustomThemeData theme) async {
final navigator = Navigator.of(context);
final messenger = ScaffoldMessenger.of(context);
final navigator = Navigator.of(context);
final messenger = ScaffoldMessenger.of(context);
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('确认删除'),
content: Text('确定要删除主题"${theme.name}"吗?此操作不可撤销。'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
onPressed: () => navigator.pop(false),
child: const Text('取消'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
onPressed: () => navigator.pop(true),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
Expand All @@ -569,15 +575,15 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
if (confirmed == true) {
try {
await _themeService.deleteCustomTheme(theme.id);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
if (!mounted) return;
messenger.showSnackBar(
SnackBar(
content: Text('主题"${theme.name}"已删除'),
backgroundColor: Colors.orange,
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('删除失败: $e'),
backgroundColor: Colors.red,
Expand All @@ -588,26 +594,27 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
}

Future<void> _importFromClipboard() async {
final messenger = ScaffoldMessenger.of(context);
try {
final theme = await _themeService.importThemeFromClipboard();
if (!context.mounted) return;
if (!mounted) return;
if (theme != null) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('主题"${theme.name}"导入成功'),
backgroundColor: Colors.green,
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
const SnackBar(
content: Text('剪贴板中没有找到有效的主题数据'),
backgroundColor: Colors.orange,
),
);
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('导入失败: $e'),
backgroundColor: Colors.red,
Expand Down Expand Up @@ -664,6 +671,7 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
}

Future<void> _importTheme(String input) async {
final messenger = ScaffoldMessenger.of(context);
try {
models.CustomThemeData theme;

Expand All @@ -673,17 +681,17 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
} else {
// 从分享码导入
theme = await _themeService.importSharedTheme(input);
if (!context.mounted) return;
if (!mounted) return;
}

ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('主题"${theme.name}"导入成功'),
backgroundColor: Colors.green,
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
messenger.showSnackBar(
SnackBar(
content: Text('导入失败: $e'),
backgroundColor: Colors.red,
Expand All @@ -693,18 +701,22 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>
}

Future<void> _resetToDefault() async {
final navigator = Navigator.of(context);
final messenger = ScaffoldMessenger.of(context);
final navigator = Navigator.of(context);
final messenger = ScaffoldMessenger.of(context);
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('重置主题'),
content: const Text('确定要重置为系统默认主题吗?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
onPressed: () => navigator.pop(false),
child: const Text('取消'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
onPressed: () => navigator.pop(true),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
foregroundColor: Colors.white,
Expand All @@ -717,8 +729,8 @@ class _ThemeManagementScreenState extends State<ThemeManagementScreen>

if (confirmed == true) {
await _themeService.resetToSystemTheme();
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
if (!mounted) return;
messenger.showSnackBar(
const SnackBar(
content: Text('已重置为系统默认主题'),
backgroundColor: Colors.green,
Expand Down