优化人物列表页

This commit is contained in:
DelLevin-Home
2026-08-09 21:05:48 +08:00
parent cd91364d13
commit 306982207e
5 changed files with 96 additions and 73 deletions

View File

@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'fade_in_local_image.dart';
/// 人物头像。
///
/// 有照片时显示照片;无照片时根据名字哈希从调色板取色,
/// 显示首字占位(同一人物始终同色)。
class PersonAvatar extends StatelessWidget {
final String? photoPath;
final String name;
final double size;
final double fontSize;
const PersonAvatar({
super.key,
required this.photoPath,
required this.name,
required this.size,
required this.fontSize,
});
// 固定调色板:背景为该色的低透明度,文字为该色本身。
static const _palette = <Color>[
Color(0xFF4A90D9), // 蓝
Color(0xFF009688), // 青
Color(0xFFE91E63), // 粉
Color(0xFF7E57C2), // 紫
Color(0xFFFF7043), // 橙
Color(0xFF4CAF50), // 绿
Color(0xFFFF9800), // 琥珀
Color(0xFF795548), // 棕
Color(0xFF5C6BC0), // 靛
Color(0xFFEC407A), // 玫红
];
Color _colorFor(String name) {
var hash = 0;
for (final c in name.codeUnits) {
hash = (hash * 31 + c) & 0x7fffffff;
}
return _palette[hash % _palette.length];
}
@override
Widget build(BuildContext context) {
final hasPhoto = photoPath != null && photoPath!.isNotEmpty;
final color = _colorFor(name);
final initial = name.isNotEmpty ? name[0] : '?';
return Container(
width: size,
height: size,
decoration: BoxDecoration(
color: hasPhoto ? null : color.withValues(alpha: 0.15),
shape: BoxShape.circle,
),
clipBehavior: Clip.antiAlias,
child: hasPhoto
? FadeInLocalImage(path: photoPath, fit: BoxFit.cover)
: Center(
child: Text(
initial,
style: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.w600,
color: color,
),
),
),
);
}
}

View File

@@ -4,6 +4,7 @@ import '../models/data_models.dart';
import '../pages/people/person_detail_page.dart';
import '../providers/app_provider.dart';
import 'fade_in_local_image.dart';
import 'person_avatar.dart';
/// 人物信息浮动面板(底部 ModalBottomSheet
/// 展示人物基本信息 + 关联作品,点击「查看全部」跳转到原详情页
@@ -130,30 +131,14 @@ class _PersonInfoSheetState extends State<PersonInfoSheet> {
}
Widget _buildHeader(Person person, ColorScheme colors) {
final hasPhoto = person.photoPath != null && person.photoPath!.isNotEmpty;
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 64,
height: 64,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
shape: BoxShape.circle,
),
clipBehavior: Clip.antiAlias,
child: hasPhoto
? FadeInLocalImage(path: person.photoPath, fit: BoxFit.cover)
: Center(
child: Text(
person.name.isNotEmpty ? person.name[0] : '?',
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.w600,
color: colors.onSurface.withValues(alpha: 0.3),
),
),
),
PersonAvatar(
photoPath: person.photoPath,
name: person.name,
size: 64,
fontSize: 26,
),
const SizedBox(width: 14),
Expanded(

View File

@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/data_models.dart';
import '../providers/app_provider.dart';
import 'fade_in_local_image.dart';
import 'person_avatar.dart';
import 'person_info_sheet.dart';
/// 作品详情页使用的"关联人物"区块
@@ -233,33 +233,17 @@ class _WorkPeopleSectionState extends State<WorkPeopleSection> {
Widget _buildPersonChip(_PersonRole item, ColorScheme colors) {
final person = item.person;
final hasPhoto = person.photoPath != null && person.photoPath!.isNotEmpty;
return GestureDetector(
onTap: () => PersonInfoSheet.show(context, person),
child: SizedBox(
width: 84,
child: Column(
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
shape: BoxShape.circle,
),
clipBehavior: Clip.antiAlias,
child: hasPhoto
? FadeInLocalImage(path: person.photoPath, fit: BoxFit.cover)
: Center(
child: Text(
person.name.isNotEmpty ? person.name[0] : '?',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w600,
color: colors.onSurface.withValues(alpha: 0.3),
),
),
),
PersonAvatar(
photoPath: person.photoPath,
name: person.name,
size: 60,
fontSize: 24,
),
const SizedBox(height: 8),
Text(