generated from dellevin/template
功能优化
This commit is contained in:
@@ -53,7 +53,15 @@ class _BookTabPageState extends State<BookTabPage> {
|
||||
}
|
||||
|
||||
if (books.isEmpty) {
|
||||
return _buildEmptyState(context, provider.bookStatusIndex);
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => await provider.loadBooks(),
|
||||
color: const Color(0xFF1A1A1A),
|
||||
backgroundColor: Colors.white,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [_buildEmptyState(context, provider.bookStatusIndex)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_layoutStyle == 1) {
|
||||
|
||||
@@ -57,7 +57,15 @@ class _MovieTabPageState extends State<MovieTabPage> {
|
||||
final movies = provider.getMoviesByStatus(currentStatus);
|
||||
|
||||
if (movies.isEmpty) {
|
||||
return _buildEmptyState(context, provider.movieStatusIndex);
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => await provider.loadMovies(),
|
||||
color: const Color(0xFF1A1A1A),
|
||||
backgroundColor: Colors.white,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [_buildEmptyState(context, provider.movieStatusIndex)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_layoutStyle == 1) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../models/data_models.dart';
|
||||
import 'note_share_page.dart';
|
||||
import '../../widgets/fade_in_local_image.dart';
|
||||
|
||||
/// 笔记详情页
|
||||
class NoteDetailPage extends StatefulWidget {
|
||||
@@ -232,12 +233,10 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
|
||||
|
||||
for (final imgPath in note.images) {
|
||||
if (imgPath.contains(path) || path.contains(imgPath)) {
|
||||
if (File(imgPath).existsSync()) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.file(File(imgPath), fit: BoxFit.cover),
|
||||
child: FadeInLocalImage(path: imgPath, fit: BoxFit.cover),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +264,7 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
|
||||
boundaryMargin: const EdgeInsets.all(20),
|
||||
minScale: 0.5,
|
||||
maxScale: 4,
|
||||
child: Image.file(File(images[initialIndex]), fit: BoxFit.contain),
|
||||
child: FadeInLocalImage(path: images[initialIndex], fit: BoxFit.contain),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../../models/data_models.dart';
|
||||
import '../../utils/user_prefs.dart';
|
||||
import '../../widgets/note_list_item.dart';
|
||||
import '../../widgets/shimmer_skeleton.dart';
|
||||
import '../../widgets/fade_in_local_image.dart';
|
||||
|
||||
/// 笔记标签页
|
||||
class NoteTabPage extends StatefulWidget {
|
||||
@@ -121,7 +122,15 @@ class _NoteTabPageState extends State<NoteTabPage> {
|
||||
}
|
||||
|
||||
if (allNotes.isEmpty && _displayedNotes.isEmpty) {
|
||||
return _buildEmptyState(context);
|
||||
return RefreshIndicator(
|
||||
onRefresh: _refresh,
|
||||
color: const Color(0xFF1A1A1A),
|
||||
backgroundColor: Colors.white,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [_buildEmptyState(context)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_layoutStyle == 1) {
|
||||
@@ -425,11 +434,10 @@ class _NoteTabPageState extends State<NoteTabPage> {
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(10)),
|
||||
child: Image.file(
|
||||
File(images.first),
|
||||
width: double.infinity,
|
||||
child: FadeInLocalImage(
|
||||
path: images.first,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const SizedBox.shrink(),
|
||||
errorWidget: const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
if (extraCount > 0)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'webdav_sync_page.dart';
|
||||
import 'server_sync_page.dart';
|
||||
|
||||
/// 云备份主页面 - 选择备份方式
|
||||
class CloudSyncPage extends StatelessWidget {
|
||||
@@ -8,225 +9,94 @@ class CloudSyncPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text('云备份'),
|
||||
),
|
||||
backgroundColor: const Color(0xFFF8F8F8),
|
||||
appBar: AppBar(title: const Text('云备份')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
padding: const EdgeInsets.all(20),
|
||||
children: [
|
||||
// 备份方式标题
|
||||
_buildSectionTitle('选择备份方式'),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// WebDAV 备份选项
|
||||
_buildSyncOption(
|
||||
context,
|
||||
const SizedBox(height: 12),
|
||||
_buildOption(
|
||||
icon: Icons.storage_outlined,
|
||||
title: 'WebDAV 备份',
|
||||
subtitle: '通过 WebDAV 协议备份到个人云盘',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const WebDAVSyncPage()),
|
||||
);
|
||||
},
|
||||
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const WebDAVSyncPage())),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 说明文字
|
||||
_buildInfoSection(),
|
||||
const SizedBox(height: 12),
|
||||
_buildOption(
|
||||
icon: Icons.sync_outlined,
|
||||
title: '服务端实时同步',
|
||||
subtitle: '自建服务端,多设备数据实时同步',
|
||||
enabled: false,
|
||||
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const ServerSyncPage())),
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
_buildInfo(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建区块标题
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A1A),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
return Row(children: [
|
||||
Container(width: 3, height: 14, decoration: BoxDecoration(color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(2))),
|
||||
const SizedBox(width: 8),
|
||||
Text(title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
]);
|
||||
}
|
||||
|
||||
/// 构建信息说明区域
|
||||
Widget _buildInfoSection() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8F8F8),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border:
|
||||
Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.info_outline,
|
||||
size: 18,
|
||||
color: Color(0xFF666666),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'关于云备份',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoItem('云备份可以将您的数据备份到远程服务器'),
|
||||
const SizedBox(height: 10),
|
||||
_buildInfoItem('支持多台设备之间的数据恢复'),
|
||||
const SizedBox(height: 10),
|
||||
_buildInfoItem('建议定期进行云备份以确保数据安全'),
|
||||
const SizedBox(height: 10),
|
||||
_buildInfoItem('首次备份可能需要较长时间,请保持网络连接'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建信息项
|
||||
Widget _buildInfoItem(String text) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.only(top: 7),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF999999),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF666666),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSyncOption(
|
||||
BuildContext context, {
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
bool enabled = true,
|
||||
}) {
|
||||
Widget _buildOption({required IconData icon, required String title, required String subtitle, required VoidCallback onTap, bool enabled = true}) {
|
||||
return GestureDetector(
|
||||
onTap: enabled ? onTap : null,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.all(18),
|
||||
decoration: BoxDecoration(
|
||||
color: enabled ? const Color(0xFFFAFAFA) : const Color(0xFFF5F5F5),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: enabled ? const Color(0xFFE8E8E8) : const Color(0xFFEEEEEE),
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: enabled ? Colors.white : const Color(0xFFEEEEEE),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: enabled
|
||||
? const Color(0xFFE8E8E8)
|
||||
: const Color(0xFFEEEEEE),
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color:
|
||||
enabled ? const Color(0xFF666666) : const Color(0xFF999999),
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: enabled
|
||||
? const Color(0xFF1A1A1A)
|
||||
: const Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: enabled
|
||||
? const Color(0xFF666666)
|
||||
: const Color(0xFF999999),
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color:
|
||||
enabled ? const Color(0xFFCCCCCC) : const Color(0xFFE5E5E5),
|
||||
),
|
||||
],
|
||||
color: enabled ? Colors.white : const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 6, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Row(children: [
|
||||
Container(width: 44, height: 44, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(10)), child: Icon(icon, color: enabled ? const Color(0xFF666666) : const Color(0xFFBBBBBB), size: 22)),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(title, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: enabled ? const Color(0xFF1A1A1A) : const Color(0xFFBBBBBB))),
|
||||
const SizedBox(height: 3),
|
||||
Text(subtitle, style: TextStyle(fontSize: 12, color: enabled ? const Color(0xFF999999) : const Color(0xFFCCCCCC))),
|
||||
])),
|
||||
Icon(Icons.chevron_right, color: enabled ? const Color(0xFFCCCCCC) : const Color(0xFFE5E5E5)),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfo() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(18),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 6, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Row(children: [
|
||||
Container(width: 36, height: 36, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(8)), child: const Icon(Icons.info_outline, size: 18, color: Color(0xFF666666))),
|
||||
const SizedBox(width: 10),
|
||||
const Text('使用说明', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
]),
|
||||
const SizedBox(height: 14),
|
||||
_infoItem('WebDAV 备份:将数据备份到支持 WebDAV 的云盘'),
|
||||
const SizedBox(height: 8),
|
||||
_infoItem('服务端实时同步:通过自建服务端实现多设备实时同步'),
|
||||
const SizedBox(height: 8),
|
||||
_infoItem('激活码由服务端管理员在管理后台生成'),
|
||||
const SizedBox(height: 8),
|
||||
_infoItem('建议定期备份 + 实时同步配合使用'),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _infoItem(String text) {
|
||||
return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Container(width: 5, height: 5, margin: const EdgeInsets.only(top: 5), decoration: BoxDecoration(color: const Color(0xFFBBBBBB), shape: BoxShape.circle)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: Text(text, style: const TextStyle(fontSize: 12, color: Color(0xFF888888), height: 1.5))),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
323
lib/pages/sync/server_sync_page.dart
Normal file
323
lib/pages/sync/server_sync_page.dart
Normal file
@@ -0,0 +1,323 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../utils/user_prefs.dart';
|
||||
import '../../utils/sync/server_sync_service.dart';
|
||||
import '../../utils/sync/server_data_service.dart';
|
||||
import '../../utils/toast_util.dart';
|
||||
|
||||
/// 服务端实时同步页面
|
||||
class ServerSyncPage extends StatefulWidget {
|
||||
const ServerSyncPage({super.key});
|
||||
|
||||
@override
|
||||
State<ServerSyncPage> createState() => _ServerSyncPageState();
|
||||
}
|
||||
|
||||
class _ServerSyncPageState extends State<ServerSyncPage> {
|
||||
final UserPrefs _prefs = UserPrefs();
|
||||
final _urlController = TextEditingController();
|
||||
final _codeController = TextEditingController();
|
||||
|
||||
bool _syncEnabled = false;
|
||||
bool _isActivated = false;
|
||||
bool _isChecking = false;
|
||||
String _expiresText = '';
|
||||
Timer? _statusTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadSettings();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_urlController.dispose();
|
||||
_codeController.dispose();
|
||||
_statusTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _loadSettings() {
|
||||
final url = _prefs.syncServerUrl;
|
||||
final code = _prefs.syncActivationCode;
|
||||
_urlController.text = url;
|
||||
_codeController.text = code;
|
||||
_isActivated = url.isNotEmpty && code.isNotEmpty;
|
||||
_syncEnabled = _isActivated && _prefs.syncEnabled;
|
||||
_updateExpiresText();
|
||||
if (_isActivated) _startStatusPolling();
|
||||
}
|
||||
|
||||
void _updateExpiresText() {
|
||||
if (_prefs.syncIsPermanent) {
|
||||
_expiresText = '永久有效';
|
||||
} else {
|
||||
final exp = _prefs.syncExpiresAt;
|
||||
if (exp.isNotEmpty) {
|
||||
try {
|
||||
final dt = DateTime.parse(exp);
|
||||
_expiresText = '有效期至 ${dt.year}-${dt.month.toString().padLeft(2, '0')}-${dt.day.toString().padLeft(2, '0')} '
|
||||
'${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
|
||||
} catch (_) {
|
||||
_expiresText = '有效期至 $exp';
|
||||
}
|
||||
} else {
|
||||
_expiresText = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _startStatusPolling() {
|
||||
_statusTimer?.cancel();
|
||||
_statusTimer = Timer.periodic(const Duration(minutes: 1), (_) => _checkStatus());
|
||||
}
|
||||
|
||||
Future<void> _checkStatus() async {
|
||||
if (!_isActivated) return;
|
||||
final result = await ServerSyncService.instance.checkActivation();
|
||||
if (!mounted) return;
|
||||
if (result == null || result['valid'] != true) {
|
||||
await _prefs.setSyncEnabled(false);
|
||||
setState(() {
|
||||
_isActivated = false;
|
||||
_syncEnabled = false;
|
||||
_expiresText = '激活码已失效';
|
||||
});
|
||||
if (mounted) ToastUtil.show(context, '激活码已失效,同步已关闭');
|
||||
} else {
|
||||
await _prefs.setSyncExpiresAt(result['expires_at'] ?? '');
|
||||
await _prefs.setSyncIsPermanent(result['is_permanent'] == true);
|
||||
_updateExpiresText();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkActivation() async {
|
||||
final url = _urlController.text.trim();
|
||||
final code = _codeController.text.trim().toUpperCase();
|
||||
if (url.isEmpty || code.isEmpty) {
|
||||
ToastUtil.show(context, '请输入服务器地址和激活码');
|
||||
return;
|
||||
}
|
||||
setState(() => _isChecking = true);
|
||||
await _prefs.setSyncServerUrl(url);
|
||||
await _prefs.setSyncActivationCode(code);
|
||||
|
||||
final result = await ServerSyncService.instance.checkActivation();
|
||||
if (!mounted) return;
|
||||
setState(() => _isChecking = false);
|
||||
|
||||
if (result != null && result['valid'] == true) {
|
||||
_isActivated = true;
|
||||
await _prefs.setSyncExpiresAt(result['expires_at'] ?? '');
|
||||
await _prefs.setSyncIsPermanent(result['is_permanent'] == true);
|
||||
_updateExpiresText();
|
||||
_startStatusPolling();
|
||||
await _prefs.setSyncEnabled(true);
|
||||
_syncEnabled = true;
|
||||
await ServerSyncService.instance.uploadToServer();
|
||||
if (mounted) ToastUtil.show(context, '激活成功,实时同步已开启');
|
||||
} else {
|
||||
final error = result?['error'] ?? '激活失败';
|
||||
if (mounted) ToastUtil.show(context, error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _toggleSync(bool value) async {
|
||||
await _prefs.setSyncEnabled(value);
|
||||
setState(() => _syncEnabled = value);
|
||||
|
||||
if (value && _isActivated) {
|
||||
await ServerSyncService.instance.uploadToServer();
|
||||
final provider = context.read<AppProvider>();
|
||||
await provider.loadMovies();
|
||||
await provider.loadBooks();
|
||||
await provider.loadNotes();
|
||||
if (mounted) ToastUtil.show(context, '已切换到服务端数据');
|
||||
} else {
|
||||
// 关闭同步:从服务端下载最新数据到本地
|
||||
if (mounted) ToastUtil.show(context, '正在从服务端同步数据...');
|
||||
final success = await ServerSyncService.instance.downloadToLocal();
|
||||
if (mounted) {
|
||||
if (success) {
|
||||
final provider = context.read<AppProvider>();
|
||||
await provider.loadMovies();
|
||||
await provider.loadBooks();
|
||||
await provider.loadNotes();
|
||||
ToastUtil.show(context, '数据已下载到本地');
|
||||
} else {
|
||||
ToastUtil.show(context, '下载失败,使用本地数据');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _disconnect() async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: const Text('断开连接', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
|
||||
content: const Text('将清除服务器配置和激活信息,确定要断开吗?', style: TextStyle(fontSize: 14, color: Color(0xFF666666))),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消', style: TextStyle(color: Color(0xFF999999)))),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定', style: TextStyle(color: Color(0xFFE53935)))),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirm != true) return;
|
||||
|
||||
_statusTimer?.cancel();
|
||||
await _toggleSync(false);
|
||||
await _prefs.setSyncServerUrl('');
|
||||
await _prefs.setSyncActivationCode('');
|
||||
await _prefs.setSyncExpiresAt('');
|
||||
await _prefs.setSyncIsPermanent(false);
|
||||
await _prefs.setSyncEnabled(false);
|
||||
|
||||
setState(() {
|
||||
_isActivated = false;
|
||||
_syncEnabled = false;
|
||||
_expiresText = '';
|
||||
_urlController.clear();
|
||||
_codeController.clear();
|
||||
});
|
||||
if (mounted) ToastUtil.show(context, '已断开连接');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8F8F8),
|
||||
appBar: AppBar(title: const Text('服务端实时同步')),
|
||||
body: ListView(padding: const EdgeInsets.all(20), children: [
|
||||
// 状态卡片
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Row(children: [
|
||||
Container(width: 10, height: 10, decoration: BoxDecoration(
|
||||
color: _isActivated ? const Color(0xFF66BB6A) : const Color(0xFFDDDDDD), shape: BoxShape.circle)),
|
||||
const SizedBox(width: 10),
|
||||
Text(_isActivated ? '已激活' : '未激活',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600,
|
||||
color: _isActivated ? const Color(0xFF66BB6A) : const Color(0xFFBBBBBB))),
|
||||
const Spacer(),
|
||||
if (_isActivated)
|
||||
GestureDetector(
|
||||
onTap: _disconnect,
|
||||
child: Container(padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
|
||||
decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(6)),
|
||||
child: const Text('断开', style: TextStyle(fontSize: 12, color: Color(0xFFE57373)))),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 20),
|
||||
const Text('服务器地址', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
|
||||
const SizedBox(height: 6),
|
||||
TextField(controller: _urlController, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
|
||||
decoration: _inputDeco('例: http://192.168.1.100:5000')),
|
||||
const SizedBox(height: 14),
|
||||
const Text('激活码', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
|
||||
const SizedBox(height: 6),
|
||||
TextField(controller: _codeController, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
|
||||
textCapitalization: TextCapitalization.characters, decoration: _inputDeco('例: MK-A1B2C3D4E5F6')),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _isChecking ? null : _checkActivation,
|
||||
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF1A1A1A), foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: const Color(0xFFDDDDDD), elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
padding: const EdgeInsets.symmetric(vertical: 13)),
|
||||
child: _isChecking
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: Text(_isActivated ? '重新验证' : '验证激活', style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
if (_expiresText.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
Center(child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(Icons.access_time, size: 14, color: _prefs.syncIsPermanent ? const Color(0xFF66BB6A) : const Color(0xFFFF9800)),
|
||||
const SizedBox(width: 6),
|
||||
Text(_expiresText, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500,
|
||||
color: _prefs.syncIsPermanent ? const Color(0xFF66BB6A) : const Color(0xFFFF9800))),
|
||||
])),
|
||||
],
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 同步开关
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 8, offset: const Offset(0, 2))]),
|
||||
child: Row(children: [
|
||||
Container(width: 44, height: 44, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(_syncEnabled ? Icons.sync : Icons.sync_disabled,
|
||||
color: _syncEnabled ? const Color(0xFF1A1A1A) : const Color(0xFFCCCCCC), size: 22)),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
const Text('服务端实时同步', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A))),
|
||||
const SizedBox(height: 2),
|
||||
Text(_syncEnabled ? '使用服务端数据,多设备实时共享' : '关闭后下载数据到本地使用',
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFFBBBBBB))),
|
||||
])),
|
||||
Switch(value: _syncEnabled, onChanged: _isActivated ? _toggleSync : null,
|
||||
activeColor: const Color(0xFF1A1A1A), activeTrackColor: const Color(0xFF1A1A1A).withOpacity(0.3),
|
||||
inactiveThumbColor: Colors.white, inactiveTrackColor: const Color(0xFFE5E5E5)),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// 说明
|
||||
Container(
|
||||
padding: const EdgeInsets.all(18),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 6, offset: const Offset(0, 2))]),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Row(children: [
|
||||
Container(width: 36, height: 36, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(8)),
|
||||
child: const Icon(Icons.info_outline, size: 18, color: Color(0xFF666666))),
|
||||
const SizedBox(width: 10),
|
||||
const Text('使用说明', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||
]),
|
||||
const SizedBox(height: 14),
|
||||
_infoItem('1. 在服务端管理后台生成激活码'),
|
||||
const SizedBox(height: 8),
|
||||
_infoItem('2. 输入服务器地址和激活码完成验证'),
|
||||
const SizedBox(height: 8),
|
||||
_infoItem('3. 验证通过后自动开启实时同步'),
|
||||
const SizedBox(height: 8),
|
||||
_infoItem('4. 开启时所有数据通过服务端接口操作'),
|
||||
const SizedBox(height: 8),
|
||||
_infoItem('5. 关闭时从服务端下载数据到本地使用'),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _inputDeco(String hint) {
|
||||
return InputDecoration(
|
||||
hintText: hint, hintStyle: const TextStyle(fontSize: 13, color: Color(0xFFCCCCCC)),
|
||||
filled: true, fillColor: const Color(0xFFF8F8F8),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: const BorderSide(color: Color(0xFF1A1A1A), width: 1)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _infoItem(String text) {
|
||||
return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Container(width: 5, height: 5, margin: const EdgeInsets.only(top: 6), decoration: BoxDecoration(color: const Color(0xFFBBBBBB), shape: BoxShape.circle)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: Text(text, style: const TextStyle(fontSize: 13, color: Color(0xFF888888), height: 1.5))),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user