382 lines
12 KiB
Dart
382 lines
12 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../core/config/settings_provider.dart';
|
|
import '../../core/theme/eda_theme.dart';
|
|
|
|
/// 设置页面
|
|
class SettingsScreen extends ConsumerWidget {
|
|
const SettingsScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final settings = ref.watch(settingsProvider);
|
|
final notifier = ref.read(settingsProvider.notifier);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('settings'),
|
|
),
|
|
body: ListView(
|
|
children: [
|
|
// 外观设置
|
|
_buildSectionHeader(context, 'appearance'),
|
|
|
|
// 主题模式
|
|
ListTile(
|
|
leading: const Icon(Icons.palette_outlined),
|
|
title: Text('darkMode'),
|
|
subtitle: Text(_getThemeModeText(settings.themeMode)),
|
|
trailing: DropdownButton<ThemeModeType>(
|
|
value: settings.themeMode,
|
|
underline: const SizedBox(),
|
|
items: [
|
|
DropdownMenuItem(
|
|
value: ThemeModeType.system,
|
|
child: Text('systemTheme'),
|
|
),
|
|
DropdownMenuItem(
|
|
value: ThemeModeType.light,
|
|
child: Text('lightMode'),
|
|
),
|
|
DropdownMenuItem(
|
|
value: ThemeModeType.dark,
|
|
child: Text('darkMode'),
|
|
),
|
|
],
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
notifier.setThemeMode(value);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
// 语言设置
|
|
ListTile(
|
|
leading: const Icon(Icons.language_outlined),
|
|
title: Text('language'),
|
|
subtitle: Text(settings.languageDisplayName),
|
|
trailing: DropdownButton<LanguageType>(
|
|
value: settings.language,
|
|
underline: const SizedBox(),
|
|
items: [
|
|
const DropdownMenuItem(
|
|
value: LanguageType.system,
|
|
child: Text('系统语言'),
|
|
),
|
|
const DropdownMenuItem(
|
|
value: LanguageType.chineseSimple,
|
|
child: Text('简体中文'),
|
|
),
|
|
const DropdownMenuItem(
|
|
value: LanguageType.chineseTraditional,
|
|
child: Text('繁體中文'),
|
|
),
|
|
const DropdownMenuItem(
|
|
value: LanguageType.english,
|
|
child: Text('English'),
|
|
),
|
|
const DropdownMenuItem(
|
|
value: LanguageType.arabic,
|
|
child: Text('العربية'),
|
|
),
|
|
],
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
notifier.setLanguage(value);
|
|
_showRestartPrompt(context);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
// 编辑器设置
|
|
_buildSectionHeader(context, 'editorSettings'),
|
|
|
|
// 网格大小
|
|
ListTile(
|
|
leading: const Icon(Icons.grid_on_outlined),
|
|
title: Text('gridSize'),
|
|
subtitle: Text('${settings.gridSize.toStringAsFixed(1)} px'),
|
|
trailing: SizedBox(
|
|
width: 150,
|
|
child: Slider(
|
|
value: settings.gridSize,
|
|
min: 5.0,
|
|
max: 50.0,
|
|
divisions: 9,
|
|
label: settings.gridSize.toStringAsFixed(1),
|
|
onChanged: (value) {
|
|
notifier.setGridSize(value);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
|
|
// 显示网格
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.grid_on),
|
|
title: Text('showGrid'),
|
|
value: settings.showGrid,
|
|
onChanged: (value) {
|
|
notifier.toggleShowGrid();
|
|
},
|
|
),
|
|
|
|
// 吸附到网格
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.magnet_outlined),
|
|
title: Text('snapToGrid'),
|
|
value: settings.snapToGrid,
|
|
onChanged: (value) {
|
|
notifier.toggleSnapToGrid();
|
|
},
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
// 保存设置
|
|
_buildSectionHeader(context, 'saveSettings'),
|
|
|
|
// 自动保存
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.save_outlined),
|
|
title: Text('autoSave'),
|
|
value: settings.autoSave,
|
|
onChanged: (value) {
|
|
notifier.setAutoSave(value);
|
|
},
|
|
),
|
|
|
|
if (settings.autoSave)
|
|
ListTile(
|
|
leading: const Icon(Icons.timer_outlined),
|
|
title: Text('autoSaveInterval'),
|
|
subtitle: Text('${settings.autoSaveIntervalMinutes} minutes'),
|
|
trailing: DropdownButton<int>(
|
|
value: settings.autoSaveIntervalMinutes,
|
|
underline: const SizedBox(),
|
|
items: [
|
|
const DropdownMenuItem(value: 1, child: Text('1 minutes')),
|
|
const DropdownMenuItem(value: 5, child: Text('5 minutes')),
|
|
const DropdownMenuItem(value: 10, child: Text('10 minutes')),
|
|
const DropdownMenuItem(value: 15, child: Text('15 minutes')),
|
|
],
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
notifier.setAutoSaveInterval(value);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
// 性能设置
|
|
_buildSectionHeader(context, 'performance'),
|
|
|
|
// 渲染质量
|
|
ListTile(
|
|
leading: const Icon(Icons.speed_outlined),
|
|
title: Text('renderQuality'),
|
|
subtitle: Text(_getRenderQualityText(settings.renderQuality)),
|
|
trailing: DropdownButton<RenderQuality>(
|
|
value: settings.renderQuality,
|
|
underline: const SizedBox(),
|
|
items: [
|
|
DropdownMenuItem(
|
|
value: RenderQuality.high,
|
|
child: Text('highQuality'),
|
|
),
|
|
DropdownMenuItem(
|
|
value: RenderQuality.balanced,
|
|
child: Text('balanced'),
|
|
),
|
|
DropdownMenuItem(
|
|
value: RenderQuality.performance,
|
|
child: Text('performanceMode'),
|
|
),
|
|
],
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
notifier.setRenderQuality(value);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
|
|
// 启用动画
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.animation_outlined),
|
|
title: Text('enableAnimations'),
|
|
value: settings.enableAnimations,
|
|
onChanged: (value) {
|
|
notifier.toggleAnimations();
|
|
},
|
|
),
|
|
|
|
// 启用抗锯齿
|
|
SwitchListTile(
|
|
secondary: const Icon(Icons.blur_on_outlined),
|
|
title: Text('enableAntialiasing'),
|
|
value: settings.enableAntialiasing,
|
|
onChanged: (value) {
|
|
notifier.toggleAntialiasing();
|
|
},
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
// 其他设置
|
|
_buildSectionHeader(context, 'otherSettings'),
|
|
|
|
// 清除缓存
|
|
ListTile(
|
|
leading: const Icon(Icons.delete_sweep_outlined),
|
|
title: Text('clearCache'),
|
|
onTap: () {
|
|
_showConfirmDialog(
|
|
context,
|
|
'clearCache',
|
|
() {
|
|
// TODO: 实现清除缓存逻辑
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('缓存已清除')),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
|
|
// 重置设置
|
|
ListTile(
|
|
leading: const Icon(Icons.restore_outlined),
|
|
title: Text('resetSettings'),
|
|
onTap: () {
|
|
_showConfirmDialog(
|
|
context,
|
|
'resetSettings',
|
|
() {
|
|
notifier.resetToDefaults();
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('设置已重置')),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
|
|
const SizedBox(height: 32),
|
|
|
|
// 版本信息
|
|
Center(
|
|
child: Column(
|
|
children: [
|
|
Text(
|
|
'version',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'1.0.0',
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 32),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSectionHeader(BuildContext context, String title) {
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 24, 16, 8),
|
|
child: Text(
|
|
title,
|
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.primary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _getThemeModeText(ThemeModeType mode) {
|
|
switch (mode) {
|
|
case ThemeModeType.system:
|
|
return 'systemTheme';
|
|
case ThemeModeType.light:
|
|
return 'lightMode';
|
|
case ThemeModeType.dark:
|
|
return 'darkMode';
|
|
}
|
|
}
|
|
|
|
String _getRenderQualityText(RenderQuality quality) {
|
|
switch (quality) {
|
|
case RenderQuality.high:
|
|
return 'highQuality';
|
|
case RenderQuality.balanced:
|
|
return 'balanced';
|
|
case RenderQuality.performance:
|
|
return 'performanceMode';
|
|
}
|
|
}
|
|
|
|
void _showRestartPrompt(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('language'),
|
|
content: const Text('语言切换后需要重启应用才能完全生效'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('ok'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
// TODO: 实现应用重启
|
|
},
|
|
child: const Text('restart'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showConfirmDialog(BuildContext context, String action, VoidCallback onConfirm) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text('confirm'),
|
|
content: Text(action == 'clearCache' ? '确定要清除缓存吗?' : '确定要重置设置吗?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('cancel'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
onConfirm();
|
|
},
|
|
child: const Text('confirm'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|