个人界面优化

This commit is contained in:
DelLevin-Home
2026-06-30 17:37:26 +08:00
parent 9fd80f83c8
commit 9430524378

View File

@@ -113,6 +113,11 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
_buildBookModule(books), _buildBookModule(books),
const SizedBox(height: 20), const SizedBox(height: 20),
], ],
if (_userPrefs.showNoteTab) ...[
_buildModuleHeader('笔记'),
_buildNoteModule(notes),
const SizedBox(height: 20),
],
_buildTagsSection(movies, books, notes), _buildTagsSection(movies, books, notes),
const SizedBox(height: 20), const SizedBox(height: 20),
_buildToolsGrid(context), _buildToolsGrid(context),
@@ -401,6 +406,80 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
); );
} }
// ─── 笔记模块 ──────────────────────────────────────────────────────
Widget _buildNoteModule(List<Note> notes) {
final recent = notes.toList()
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
if (recent.isEmpty) return _buildEmptyHint('暂无笔记记录');
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
SizedBox(
height: 130,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 20),
itemCount: recent.take(8).length,
separatorBuilder: (_, __) => const SizedBox(width: 10),
itemBuilder: (_, i) => _buildNoteCard(
title: recent[i].title,
content: recent[i].content,
onTap: () => Navigator.pushNamed(context, '/note-detail',
arguments: recent[i]),
),
),
),
],
);
}
Widget _buildNoteCard({
required String title,
required String content,
VoidCallback? onTap,
}) {
final colors = Theme.of(context).colorScheme;
return GestureDetector(
onTap: onTap,
child: Container(
width: 115,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(10),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (title.isNotEmpty) ...[
Text(title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: colors.onSurface)),
const SizedBox(height: 6),
],
Expanded(
child: Text(content,
maxLines: title.isNotEmpty ? 5 : 6,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 11,
height: 1.5,
color: colors.onSurface.withValues(alpha: 0.55))),
),
],
),
),
);
}
Widget _buildStatusTag( Widget _buildStatusTag(
String label, int count, bool active, ColorScheme colors) { String label, int count, bool active, ColorScheme colors) {
return Row( return Row(
@@ -2139,13 +2218,41 @@ class _MainContentSettingsPageState extends State<MainContentSettingsPage> {
return count; return count;
} }
/// 获取当前启用的标签页列表,返回 (索引, 标签, 图标) 列表
List<(int, String, IconData)> get _enabledTabs {
final all = [
(0, '影视', Icons.movie_outlined),
(1, '阅读', Icons.menu_book_outlined),
(2, '笔记', Icons.note_outlined),
];
return all.where((t) {
return switch (t.$1) {
0 => _showMovieTab,
1 => _showBookTab,
2 => _showNoteTab,
_ => false,
};
}).toList();
}
void _fixDefaultTabIndex() {
final enabled = _enabledTabs;
if (!enabled.any((t) => t.$1 == _defaultTabIndex) && enabled.isNotEmpty) {
_defaultTabIndex = enabled.first.$1;
_userPrefs.setDefaultMainTabIndex(_defaultTabIndex);
}
}
Future<void> _toggleMovieTab(bool value) async { Future<void> _toggleMovieTab(bool value) async {
if (!value && _enabledTabCount <= 1) { if (!value && _enabledTabCount <= 1) {
ToastUtil.show(context, '至少保留一个标签页'); ToastUtil.show(context, '至少保留一个标签页');
return; return;
} }
await _userPrefs.setShowMovieTab(value); await _userPrefs.setShowMovieTab(value);
setState(() => _showMovieTab = value); setState(() {
_showMovieTab = value;
_fixDefaultTabIndex();
});
} }
Future<void> _toggleBookTab(bool value) async { Future<void> _toggleBookTab(bool value) async {
@@ -2154,7 +2261,10 @@ class _MainContentSettingsPageState extends State<MainContentSettingsPage> {
return; return;
} }
await _userPrefs.setShowBookTab(value); await _userPrefs.setShowBookTab(value);
setState(() => _showBookTab = value); setState(() {
_showBookTab = value;
_fixDefaultTabIndex();
});
} }
Future<void> _toggleNoteTab(bool value) async { Future<void> _toggleNoteTab(bool value) async {
@@ -2163,7 +2273,10 @@ class _MainContentSettingsPageState extends State<MainContentSettingsPage> {
return; return;
} }
await _userPrefs.setShowNoteTab(value); await _userPrefs.setShowNoteTab(value);
setState(() => _showNoteTab = value); setState(() {
_showNoteTab = value;
_fixDefaultTabIndex();
});
} }
Future<void> _toggleNotePlusTab(bool value) async { Future<void> _toggleNotePlusTab(bool value) async {
@@ -2272,49 +2385,50 @@ class _MainContentSettingsPageState extends State<MainContentSettingsPage> {
Widget _buildDefaultTabSelector() { Widget _buildDefaultTabSelector() {
final colors = Theme.of(context).colorScheme; final colors = Theme.of(context).colorScheme;
final labels = ['影视', '阅读', '笔记']; final enabled = _enabledTabs;
final icons = [ final currentLabel = enabled
Icons.movie_outlined, .firstWhere((t) => t.$1 == _defaultTabIndex,
Icons.menu_book_outlined, orElse: () => enabled.first)
Icons.note_outlined .$2;
];
return ListTile( return InkWell(
contentPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 4), onTap: _showDefaultTabPicker,
leading: Container( child: Container(
width: 36, padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
height: 36, child: Row(
decoration: BoxDecoration( children: [
color: colors.surfaceContainerHighest, Container(
borderRadius: BorderRadius.circular(10)), width: 36,
child: Icon(Icons.home_outlined, height: 36,
color: colors.onSurface.withValues(alpha: 0.6), size: 18)), decoration: BoxDecoration(
title: Text('默认启动标签', color: colors.surfaceContainerHighest,
style: TextStyle( borderRadius: BorderRadius.circular(10)),
fontSize: 13, child: Icon(Icons.home_outlined,
fontWeight: FontWeight.w500, color: colors.onSurface.withValues(alpha: 0.6), size: 18)),
color: colors.onSurface)), const SizedBox(width: 12),
subtitle: Text('打开应用时默认显示的页面', Expanded(
style: TextStyle( child: Text('默认启动标签',
fontSize: 11, color: colors.onSurface.withValues(alpha: 0.4))), style: TextStyle(
trailing: Row( fontSize: 13,
mainAxisSize: MainAxisSize.min, fontWeight: FontWeight.w500,
children: [ color: colors.onSurface)),
Text(labels[_defaultTabIndex], ),
style: TextStyle( Text(currentLabel,
fontSize: 14, style: TextStyle(
color: colors.onSurface.withValues(alpha: 0.4))), fontSize: 13,
const SizedBox(width: 4), color: colors.onSurface.withValues(alpha: 0.5))),
Icon(Icons.chevron_right, const SizedBox(width: 4),
color: colors.onSurface.withValues(alpha: 0.25), size: 20), Icon(Icons.chevron_right,
], size: 18, color: colors.onSurface.withValues(alpha: 0.25)),
],
),
), ),
onTap: () => _showDefaultTabPicker(labels, icons),
); );
} }
void _showDefaultTabPicker(List<String> labels, List<IconData> icons) { void _showDefaultTabPicker() {
final colors = Theme.of(context).colorScheme; final colors = Theme.of(context).colorScheme;
final enabled = _enabledTabs;
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
@@ -2344,7 +2458,7 @@ class _MainContentSettingsPageState extends State<MainContentSettingsPage> {
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: colors.onSurface)))), color: colors.onSurface)))),
const SizedBox(height: 16), const SizedBox(height: 16),
for (int i = 0; i < labels.length; i++) for (final t in enabled)
ListTile( ListTile(
leading: Container( leading: Container(
width: 36, width: 36,
@@ -2352,19 +2466,19 @@ class _MainContentSettingsPageState extends State<MainContentSettingsPage> {
decoration: BoxDecoration( decoration: BoxDecoration(
color: colors.surfaceContainerHighest, color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(10)), borderRadius: BorderRadius.circular(10)),
child: Icon(icons[i], child: Icon(t.$3,
color: colors.onSurface.withValues(alpha: 0.6))), color: colors.onSurface.withValues(alpha: 0.6))),
title: Text(labels[i], title: Text(t.$2,
style: TextStyle( style: TextStyle(
fontSize: 13, fontSize: 13,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: colors.onSurface)), color: colors.onSurface)),
trailing: _defaultTabIndex == i trailing: _defaultTabIndex == t.$1
? Icon(Icons.check, color: colors.onSurface, size: 20) ? Icon(Icons.check, color: colors.onSurface, size: 20)
: null, : null,
onTap: () async { onTap: () async {
await _userPrefs.setDefaultMainTabIndex(i); await _userPrefs.setDefaultMainTabIndex(t.$1);
setState(() => _defaultTabIndex = i); setState(() => _defaultTabIndex = t.$1);
Navigator.pop(ctx); Navigator.pop(ctx);
}, },
), ),