generated from dellevin/template
优化人物列表页
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../../providers/app_provider.dart';
|
import '../../providers/app_provider.dart';
|
||||||
import '../../models/data_models.dart';
|
import '../../models/data_models.dart';
|
||||||
|
import '../../widgets/person_avatar.dart';
|
||||||
import '../movies/movie_detail_page.dart';
|
import '../movies/movie_detail_page.dart';
|
||||||
import '../book/book_detail_page.dart';
|
import '../book/book_detail_page.dart';
|
||||||
|
|
||||||
@@ -214,13 +215,11 @@ class _PersonListPageState extends State<PersonListPage> {
|
|||||||
final totalWorks = person.movies.length + person.books.length;
|
final totalWorks = person.movies.length + person.books.length;
|
||||||
return ListTile(
|
return ListTile(
|
||||||
contentPadding: const EdgeInsets.symmetric(vertical: 4),
|
contentPadding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
leading: CircleAvatar(
|
leading: PersonAvatar(
|
||||||
radius: 20,
|
photoPath: null,
|
||||||
backgroundColor: colors.surfaceContainerHighest,
|
name: person.name,
|
||||||
child: Text(
|
size: 40,
|
||||||
person.name.isNotEmpty ? person.name[0] : '?',
|
fontSize: 16,
|
||||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: colors.onSurface.withValues(alpha: 0.5)),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
title: Text(person.name, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
title: Text(person.name, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||||
subtitle: Padding(
|
subtitle: Padding(
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import '../../models/data_models.dart';
|
|||||||
import '../../providers/app_provider.dart';
|
import '../../providers/app_provider.dart';
|
||||||
import '../../utils/responsive.dart';
|
import '../../utils/responsive.dart';
|
||||||
import '../../utils/toast_util.dart';
|
import '../../utils/toast_util.dart';
|
||||||
import '../../widgets/fade_in_local_image.dart';
|
import '../../widgets/person_avatar.dart';
|
||||||
import 'person_detail_page.dart';
|
import 'person_detail_page.dart';
|
||||||
import 'person_form_page.dart';
|
import 'person_form_page.dart';
|
||||||
|
|
||||||
@@ -211,7 +211,6 @@ class _PersonListPageState extends State<PersonListPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPersonItem(Person person, ColorScheme colors) {
|
Widget _buildPersonItem(Person person, ColorScheme colors) {
|
||||||
final hasPhoto = person.photoPath != null && person.photoPath!.isNotEmpty;
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => _navigateToDetail(person),
|
onTap: () => _navigateToDetail(person),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
@@ -224,27 +223,11 @@ class _PersonListPageState extends State<PersonListPage> {
|
|||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
// 头像
|
PersonAvatar(
|
||||||
Container(
|
photoPath: person.photoPath,
|
||||||
width: 48,
|
name: person.name,
|
||||||
height: 48,
|
size: 48,
|
||||||
decoration: BoxDecoration(
|
fontSize: 20,
|
||||||
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: 20,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: colors.onSurface.withValues(alpha: 0.4),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
// 信息
|
// 信息
|
||||||
|
|||||||
72
lib/widgets/person_avatar.dart
Normal file
72
lib/widgets/person_avatar.dart
Normal 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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import '../models/data_models.dart';
|
|||||||
import '../pages/people/person_detail_page.dart';
|
import '../pages/people/person_detail_page.dart';
|
||||||
import '../providers/app_provider.dart';
|
import '../providers/app_provider.dart';
|
||||||
import 'fade_in_local_image.dart';
|
import 'fade_in_local_image.dart';
|
||||||
|
import 'person_avatar.dart';
|
||||||
|
|
||||||
/// 人物信息浮动面板(底部 ModalBottomSheet)
|
/// 人物信息浮动面板(底部 ModalBottomSheet)
|
||||||
/// 展示人物基本信息 + 关联作品,点击「查看全部」跳转到原详情页
|
/// 展示人物基本信息 + 关联作品,点击「查看全部」跳转到原详情页
|
||||||
@@ -130,30 +131,14 @@ class _PersonInfoSheetState extends State<PersonInfoSheet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildHeader(Person person, ColorScheme colors) {
|
Widget _buildHeader(Person person, ColorScheme colors) {
|
||||||
final hasPhoto = person.photoPath != null && person.photoPath!.isNotEmpty;
|
|
||||||
return Row(
|
return Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
PersonAvatar(
|
||||||
width: 64,
|
photoPath: person.photoPath,
|
||||||
height: 64,
|
name: person.name,
|
||||||
decoration: BoxDecoration(
|
size: 64,
|
||||||
color: colors.surfaceContainerHighest,
|
fontSize: 26,
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 14),
|
const SizedBox(width: 14),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../models/data_models.dart';
|
import '../models/data_models.dart';
|
||||||
import '../providers/app_provider.dart';
|
import '../providers/app_provider.dart';
|
||||||
import 'fade_in_local_image.dart';
|
import 'person_avatar.dart';
|
||||||
import 'person_info_sheet.dart';
|
import 'person_info_sheet.dart';
|
||||||
|
|
||||||
/// 作品详情页使用的"关联人物"区块
|
/// 作品详情页使用的"关联人物"区块
|
||||||
@@ -233,33 +233,17 @@ class _WorkPeopleSectionState extends State<WorkPeopleSection> {
|
|||||||
|
|
||||||
Widget _buildPersonChip(_PersonRole item, ColorScheme colors) {
|
Widget _buildPersonChip(_PersonRole item, ColorScheme colors) {
|
||||||
final person = item.person;
|
final person = item.person;
|
||||||
final hasPhoto = person.photoPath != null && person.photoPath!.isNotEmpty;
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => PersonInfoSheet.show(context, person),
|
onTap: () => PersonInfoSheet.show(context, person),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 84,
|
width: 84,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
PersonAvatar(
|
||||||
width: 60,
|
photoPath: person.photoPath,
|
||||||
height: 60,
|
name: person.name,
|
||||||
decoration: BoxDecoration(
|
size: 60,
|
||||||
color: colors.surfaceContainerHighest,
|
fontSize: 24,
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
Reference in New Issue
Block a user