generated from dellevin/template
v0.1.9版本发布
This commit is contained in:
@@ -67,9 +67,7 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
children: [
|
||||
_buildAppBar(context),
|
||||
_buildTabBar(context),
|
||||
Expanded(
|
||||
child: _buildTabContent(),
|
||||
),
|
||||
Expanded(child: _buildTabContent()),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -83,14 +81,7 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
_buildCloudSyncButton(context),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SearchPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const SearchPage())),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -99,268 +90,156 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
}
|
||||
|
||||
Widget _buildCloudSyncButton(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return PopupMenuButton<String>(
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.cloud_sync_outlined),
|
||||
tooltip: '云备份',
|
||||
offset: const Offset(0, 40),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'upload',
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.cloud_upload_outlined,
|
||||
size: 18,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
),
|
||||
onPressed: () => _showCloudSheet(context),
|
||||
);
|
||||
}
|
||||
|
||||
void _showCloudSheet(BuildContext context) async {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final hasConfig = (await WebDAVService.instance.getConfig()) != null;
|
||||
|
||||
if (!mounted) return;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: colors.surface,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
|
||||
builder: (ctx) {
|
||||
final bc = Theme.of(ctx).colorScheme;
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 24),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Center(child: Container(
|
||||
width: 40, height: 4, margin: const EdgeInsets.only(bottom: 20),
|
||||
decoration: BoxDecoration(color: bc.onSurface.withValues(alpha: 0.15), borderRadius: BorderRadius.circular(2)),
|
||||
)),
|
||||
Text('云备份', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: bc.onSurface)),
|
||||
const SizedBox(height: 20),
|
||||
_cloudCard(
|
||||
icon: Icons.cloud_upload_outlined,
|
||||
title: '上传数据',
|
||||
desc: hasConfig ? '将本地数据同步到云端' : '请先配置 WebDAV 服务器',
|
||||
onTap: hasConfig ? () { Navigator.pop(ctx); _performSync(context, SyncDirection.upload); } : null,
|
||||
enabled: hasConfig,
|
||||
colors: bc,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'上传数据',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_cloudCard(
|
||||
icon: Icons.cloud_download_outlined,
|
||||
title: '下载数据',
|
||||
desc: hasConfig ? '从云端恢复数据到本地' : '请先配置 WebDAV 服务器',
|
||||
onTap: hasConfig ? () { Navigator.pop(ctx); _performSync(context, SyncDirection.download); } : null,
|
||||
enabled: hasConfig,
|
||||
colors: bc,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
_cloudCard(
|
||||
icon: Icons.settings_outlined,
|
||||
title: 'WebDAV 设置',
|
||||
desc: '配置服务器地址与认证信息',
|
||||
onTap: () { Navigator.pop(ctx); Navigator.push(context, MaterialPageRoute(builder: (_) => const WebDAVSyncPage())); },
|
||||
enabled: true,
|
||||
colors: bc,
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'download',
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.cloud_download_outlined,
|
||||
size: 18,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'下载数据',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
value: 'settings',
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.settings_outlined,
|
||||
size: 18,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'WebDAV设置',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
onSelected: (value) async {
|
||||
switch (value) {
|
||||
case 'upload':
|
||||
await _performSync(context, SyncDirection.upload);
|
||||
break;
|
||||
case 'download':
|
||||
await _performSync(context, SyncDirection.download);
|
||||
break;
|
||||
case 'settings':
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const WebDAVSyncPage(),
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cloudCard({required IconData icon, required String title, required String desc, required bool enabled, required VoidCallback? onTap, required ColorScheme colors}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: enabled ? colors.primary.withValues(alpha: 0.04) : colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: enabled ? colors.primary.withValues(alpha: 0.1) : colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 48, height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: enabled ? colors.primary.withValues(alpha: 0.08) : colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(icon, size: 24, color: enabled ? colors.primary : colors.onSurface.withValues(alpha: 0.18)),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(title, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: enabled ? colors.onSurface : colors.onSurface.withValues(alpha: 0.25))),
|
||||
const SizedBox(height: 2),
|
||||
Text(desc, style: TextStyle(fontSize: 12, color: enabled ? colors.onSurface.withValues(alpha: 0.4) : colors.onSurface.withValues(alpha: 0.2))),
|
||||
])),
|
||||
Icon(Icons.chevron_right, size: 20, color: enabled ? colors.onSurface.withValues(alpha: 0.15) : colors.onSurface.withValues(alpha: 0.08)),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _performSync(BuildContext context, SyncDirection direction) async {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final config = await WebDAVService.instance.getConfig();
|
||||
if (config == null) {
|
||||
if (context.mounted) {
|
||||
_showResultDialog(
|
||||
context,
|
||||
title: '同步失败',
|
||||
message: '请先配置 WebDAV 服务器',
|
||||
isSuccess: false,
|
||||
);
|
||||
}
|
||||
if (context.mounted) _showResultDialog(context, title: '同步失败', message: '请先配置 WebDAV 服务器', isSuccess: false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: colors.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
showDialog(context: context, barrierDismissible: false, builder: (_) => Center(child: CircularProgressIndicator(color: colors.primary)));
|
||||
}
|
||||
|
||||
final result = await WebDAVService.instance.syncData(direction: direction);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
if (result.success && result.needReload && context.mounted) {
|
||||
final provider = context.read<AppProvider>();
|
||||
await provider.loadMovies();
|
||||
await provider.loadBooks();
|
||||
await provider.loadNotes();
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
final isSuccess = result.success;
|
||||
final message = result.message.isNotEmpty ? result.message : (isSuccess ? '同步成功' : '同步失败');
|
||||
|
||||
_showResultDialog(
|
||||
context,
|
||||
title: isSuccess ? '同步成功' : '同步失败',
|
||||
message: message,
|
||||
isSuccess: isSuccess,
|
||||
details: {
|
||||
'uploaded': result.uploadedFiles + result.uploadedImages,
|
||||
'downloaded': result.downloadedFiles + result.downloadedImages,
|
||||
},
|
||||
_showResultDialog(context,
|
||||
title: result.success ? '同步成功' : '同步失败',
|
||||
message: result.message.isNotEmpty ? result.message : (result.success ? '同步成功' : '同步失败'),
|
||||
isSuccess: result.success,
|
||||
details: {'uploaded': result.uploadedFiles + result.uploadedImages, 'downloaded': result.downloadedFiles + result.downloadedImages},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showResultDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String message,
|
||||
required bool isSuccess,
|
||||
Map<String, dynamic>? details,
|
||||
}) {
|
||||
void _showResultDialog(BuildContext context, {required String title, required String message, required bool isSuccess, Map<String, dynamic>? details}) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: colors.surface, elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: isSuccess ? const Color(0xFFE8F5E9) : const Color(0xFFFFEBEE),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(
|
||||
isSuccess ? Icons.check_circle : Icons.error,
|
||||
color: isSuccess ? const Color(0xFF4CAF50) : const Color(0xFFE57373),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
),
|
||||
title: Row(children: [
|
||||
Container(
|
||||
width: 40, height: 40,
|
||||
decoration: BoxDecoration(color: isSuccess ? const Color(0xFFE8F5E9) : const Color(0xFFFFEBEE), borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(isSuccess ? Icons.check_circle : Icons.error, color: isSuccess ? const Color(0xFF4CAF50) : const Color(0xFFE57373), size: 24),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(title, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
]),
|
||||
content: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(message, style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5)),
|
||||
if (details != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Container(padding: const EdgeInsets.all(12), decoration: BoxDecoration(color: colors.surfaceContainerHigh, borderRadius: BorderRadius.circular(8)), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
if (details['uploaded'] != null) _detailRow('上传文件', '${details['uploaded']} 个', colors),
|
||||
if (details['downloaded'] != null) _detailRow('下载文件', '${details['downloaded']} 个', colors),
|
||||
])),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
if (details != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (details['uploaded'] != null)
|
||||
_buildDetailRow('上传文件', '${details['uploaded']} 个'),
|
||||
if (details['downloaded'] != null)
|
||||
_buildDetailRow('下载文件', '${details['downloaded']} 个'),
|
||||
if (details['conflicts'] != null)
|
||||
_buildDetailRow('冲突处理', '${details['conflicts']} 个'),
|
||||
if (details['errors'] != null && details['errors'] > 0)
|
||||
_buildDetailRow('错误', '${details['errors']} 个', isError: true),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
]),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colors.primary,
|
||||
foregroundColor: colors.onPrimary,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: colors.primary, foregroundColor: colors.onPrimary, elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12)),
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
@@ -369,56 +248,20 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String label, String value, {bool isError = false}) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: colors.onSurface.withValues(alpha: 0.4),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isError ? const Color(0xFFE57373) : colors.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
Widget _detailRow(String label, String value, ColorScheme colors) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Text(label, style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
Text(value, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
]),
|
||||
);
|
||||
|
||||
String _getAppBarTitle(AppProvider provider) {
|
||||
switch (provider.mainTabIndex) {
|
||||
case 0:
|
||||
return '影视';
|
||||
case 1:
|
||||
return '阅读';
|
||||
case 2:
|
||||
return '笔记';
|
||||
default:
|
||||
return 'MookNote';
|
||||
}
|
||||
}
|
||||
|
||||
IconData _getTabIcon(String label) {
|
||||
switch (label) {
|
||||
case '影视':
|
||||
return Icons.movie_outlined;
|
||||
case '阅读':
|
||||
return Icons.menu_book_outlined;
|
||||
case '笔记':
|
||||
return Icons.notes;
|
||||
default:
|
||||
return Icons.circle;
|
||||
case 0: return '影视';
|
||||
case 1: return '阅读';
|
||||
case 2: return '笔记';
|
||||
default: return 'MookNote';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,88 +270,65 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
builder: (context, provider, child) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final tabs = _enabledTabs;
|
||||
final currentEnabledIndex = _mapToEnabledTabIndex(provider.mainTabIndex);
|
||||
final safeIndex = currentEnabledIndex < tabs.length ? currentEnabledIndex : 0;
|
||||
final safeIndex = _mapToEnabledTabIndex(provider.mainTabIndex).clamp(0, tabs.length - 1);
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 20, right: 20, top: 14),
|
||||
child: Row(
|
||||
children: tabs.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final tab = entry.value;
|
||||
final isSelected = index == safeIndex;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => provider.setMainTabIndex(tab.originalIndex),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
_getTabIcon(tab.label),
|
||||
size: 22,
|
||||
color: isSelected ? colors.primary : colors.onSurface.withValues(alpha: 0.35),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
tab.label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
color: isSelected ? colors.primary : colors.onSurface.withValues(alpha: 0.35),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
color: colors.surface,
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Row(
|
||||
children: tabs.asMap().entries.map((entry) {
|
||||
final idx = entry.key;
|
||||
final tab = entry.value;
|
||||
final selected = idx == safeIndex;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => provider.setMainTabIndex(tab.originalIndex),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
_tabIcon(tab.label),
|
||||
size: 18,
|
||||
color: selected ? colors.primary : colors.onSurface.withValues(alpha: 0.3),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text(tab.label, textAlign: TextAlign.center, style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
color: selected ? colors.primary : colors.onSurface.withValues(alpha: 0.3),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final indicatorWidth = 24.0;
|
||||
final tabWidth = constraints.maxWidth / tabs.length;
|
||||
final indicatorLeft = safeIndex * tabWidth + (tabWidth - indicatorWidth) / 2;
|
||||
return SizedBox(
|
||||
height: 3,
|
||||
child: Stack(
|
||||
children: [
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 600),
|
||||
curve: Curves.easeInOut,
|
||||
left: indicatorLeft,
|
||||
top: 0,
|
||||
child: Container(
|
||||
width: indicatorWidth,
|
||||
height: 3,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary,
|
||||
borderRadius: BorderRadius.circular(1.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final tabWidth = tabs.isNotEmpty ? constraints.maxWidth / tabs.length : 0.0;
|
||||
return SizedBox(height: 2.5, child: Stack(children: [
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 300), curve: Curves.easeInOut,
|
||||
left: safeIndex * tabWidth, top: 0,
|
||||
width: tabWidth,
|
||||
child: Container(height: 2.5, decoration: BoxDecoration(color: colors.primary, borderRadius: BorderRadius.circular(2))),
|
||||
),
|
||||
]));
|
||||
},
|
||||
),
|
||||
Divider(height: 0.5, thickness: 0.5, color: colors.outline),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -519,97 +339,45 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
builder: (context, provider, child) {
|
||||
final tabs = _enabledTabs;
|
||||
_TabItem? currentTab;
|
||||
for (final tab in tabs) {
|
||||
if (tab.originalIndex == provider.mainTabIndex) {
|
||||
currentTab = tab;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (final tab in tabs) { if (tab.originalIndex == provider.mainTabIndex) { currentTab = tab; break; } }
|
||||
if (currentTab == null && tabs.isNotEmpty) {
|
||||
currentTab = tabs.first;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
provider.setMainTabIndex(currentTab!.originalIndex);
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => provider.setMainTabIndex(currentTab!.originalIndex));
|
||||
}
|
||||
|
||||
if (currentTab == null) {
|
||||
return const Center(child: Text('请至少启用一个标签页'));
|
||||
}
|
||||
|
||||
if (currentTab == null) return const Center(child: Text('请至少启用一个标签页'));
|
||||
switch (currentTab.originalIndex) {
|
||||
case 0:
|
||||
return const MovieTabPage();
|
||||
case 1:
|
||||
return const BookTabPage();
|
||||
case 2:
|
||||
return const NoteTabPage();
|
||||
default:
|
||||
return const MovieTabPage();
|
||||
case 0: return const MovieTabPage();
|
||||
case 1: return const BookTabPage();
|
||||
case 2: return const NoteTabPage();
|
||||
default: return const MovieTabPage();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
IconData _tabIcon(String label) {
|
||||
switch (label) {
|
||||
case '影视': return Icons.movie_outlined;
|
||||
case '阅读': return Icons.menu_book_outlined;
|
||||
case '笔记': return Icons.note_outlined;
|
||||
default: return Icons.circle;
|
||||
}
|
||||
}
|
||||
|
||||
void _showAddDialog(BuildContext context, AppProvider provider) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: colors.surface,
|
||||
context: context, backgroundColor: colors.surface,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||
builder: (BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Wrap(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.movie, color: colors.onSurface),
|
||||
title: const Text('添加观影'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
final statusMap = {
|
||||
0: 'watched',
|
||||
1: 'watching',
|
||||
2: 'want_to_watch',
|
||||
};
|
||||
final currentStatus = statusMap[provider.movieStatusIndex] ?? 'want_to_watch';
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/movie-form',
|
||||
arguments: {'initialStatus': currentStatus},
|
||||
);
|
||||
},
|
||||
),
|
||||
Divider(height: 0.5, indent: 56, color: colors.outlineVariant),
|
||||
ListTile(
|
||||
leading: Icon(Icons.menu_book, color: colors.onSurface),
|
||||
title: const Text('添加阅读'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
final statusMap = {
|
||||
0: 'read',
|
||||
1: 'reading',
|
||||
2: 'want_to_read',
|
||||
};
|
||||
final currentStatus = statusMap[provider.bookStatusIndex] ?? 'want_to_read';
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/book-form',
|
||||
arguments: {'initialStatus': currentStatus},
|
||||
);
|
||||
},
|
||||
),
|
||||
Divider(height: 0.5, indent: 56, color: colors.outlineVariant),
|
||||
ListTile(
|
||||
leading: Icon(Icons.note, color: colors.onSurface),
|
||||
title: const Text('添加笔记'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, '/note-form');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
builder: (_) => SafeArea(
|
||||
child: Wrap(children: [
|
||||
ListTile(leading: Icon(Icons.movie, color: colors.onSurface), title: const Text('添加观影'), onTap: () { Navigator.pop(context); Navigator.pushNamed(context, '/movie-form', arguments: {'initialStatus': ['watched', 'watching', 'want_to_watch'][provider.movieStatusIndex]}); }),
|
||||
Divider(height: 0.5, indent: 56, color: colors.outlineVariant),
|
||||
ListTile(leading: Icon(Icons.menu_book, color: colors.onSurface), title: const Text('添加阅读'), onTap: () { Navigator.pop(context); Navigator.pushNamed(context, '/book-form', arguments: {'initialStatus': ['read', 'reading', 'want_to_read'][provider.bookStatusIndex]}); }),
|
||||
Divider(height: 0.5, indent: 56, color: colors.outlineVariant),
|
||||
ListTile(leading: Icon(Icons.note, color: colors.onSurface), title: const Text('添加笔记'), onTap: () { Navigator.pop(context); Navigator.pushNamed(context, '/note-form'); }),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -617,6 +385,5 @@ class _MainContentPageState extends State<MainContentPage> {
|
||||
class _TabItem {
|
||||
final String label;
|
||||
final int originalIndex;
|
||||
|
||||
_TabItem(this.label, this.originalIndex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user