优化图库界面

This commit is contained in:
DelLevin-Home
2026-08-10 21:09:52 +08:00
parent ceb51afd03
commit 5060cae626
4 changed files with 153 additions and 86 deletions

View File

@@ -41,6 +41,9 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
// 我的模块切换索引 (0=影视, 1=阅读, 2=游戏, 3=笔记)
int _myModuleIndex = 0;
// Hero 背景封面路径缓存,避免每次 build 都 shuffle 换图
List<String> _heroCoverPaths = const [];
@override
void initState() {
super.initState();
@@ -61,8 +64,13 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
@override
void didPopNext() {
// 从其他页面返回时刷新用户数据(头像、昵称等)
// 从其他页面返回时刷新用户数据(头像、昵称等)+ 换一次背景图
_loadUserData();
_invalidateHeroCache();
}
void _invalidateHeroCache() {
setState(() => _heroCoverPaths = const []);
}
Future<void> _loadUserData() async {
@@ -129,14 +137,18 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
Widget _buildHero(List<Movie> movies, List<Book> books, List<Note> notes, List<Game> games) {
final colors = Theme.of(context).colorScheme;
final coverPaths = [
...movies
.where((m) => m.posterPath != null && m.posterPath!.isNotEmpty)
.map((m) => m.posterPath!),
...books
.where((b) => b.coverPath != null && b.coverPath!.isNotEmpty)
.map((b) => b.coverPath!),
]..shuffle();
// 仅在缓存为空时重新生成(进入页面 / 从其他页面返回),避免每次 build 都 shuffle 换图
if (_heroCoverPaths.isEmpty) {
_heroCoverPaths = [
...movies
.where((m) => m.posterPath != null && m.posterPath!.isNotEmpty)
.map((m) => m.posterPath!),
...books
.where((b) => b.coverPath != null && b.coverPath!.isNotEmpty)
.map((b) => b.coverPath!),
]..shuffle();
}
final coverPaths = _heroCoverPaths;
final hasData = coverPaths.length >= 4;

View File

@@ -218,25 +218,18 @@ class _WatchlistPageState extends State<WatchlistPage> {
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(6),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 封面
Container(
width: 52,
height: 74,
width: 56,
height: 80,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(6),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.08),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
borderRadius: BorderRadius.circular(4),
),
clipBehavior: Clip.antiAlias,
child: item.imagePath != null && item.imagePath!.isNotEmpty
@@ -248,23 +241,12 @@ class _WatchlistPageState extends State<WatchlistPage> {
: Icon(Icons.image_outlined,
size: 18, color: colors.onSurface.withValues(alpha: 0.2)),
),
const SizedBox(width: 10),
// 左侧竖色条
Container(
width: 3,
height: 50,
decoration: BoxDecoration(
color: _typeColor[item.type]!.withValues(alpha: 0.6),
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 10),
// 标题 + 类型
const SizedBox(width: 12),
// 标题 + 底部信息
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 2),
Text(item.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
@@ -273,7 +255,7 @@ class _WatchlistPageState extends State<WatchlistPage> {
fontWeight: FontWeight.w500,
color: colors.onSurface,
height: 1.3)),
const SizedBox(height: 6),
const SizedBox(height: 8),
Row(
children: [
Icon(_typeIcon[item.type],
@@ -284,21 +266,16 @@ class _WatchlistPageState extends State<WatchlistPage> {
fontSize: 11,
fontWeight: FontWeight.w500,
color: _typeColor[item.type])),
const Spacer(),
Text(_formatRelative(item.createdAt),
style: TextStyle(
fontSize: 11,
color: colors.onSurface.withValues(alpha: 0.4))),
],
),
],
),
),
// 右侧加入时间
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(_formatRelative(item.createdAt),
style: TextStyle(
fontSize: 11,
color: colors.onSurface.withValues(alpha: 0.4))),
],
),
],
),
),