添加角色信息编辑

This commit is contained in:
DelLevin-Home
2026-08-09 01:22:35 +08:00
parent df8335b187
commit c95a659921
17 changed files with 2657 additions and 14 deletions

View File

@@ -0,0 +1,248 @@
import 'package:flutter/material.dart';
import '../pages/character/character_form_page.dart';
import 'fade_in_local_image.dart';
/// 角色信息底部弹窗
///
/// 展示角色详情,提供编辑入口。
/// [entityType] = 'movie' / 'book' / 'game'
/// [entityId] = 所属作品 ID
/// [character] = MovieCharacter / BookCharacter / GameCharacter
class CharacterInfoSheet extends StatefulWidget {
final String entityType;
final String entityId;
final dynamic character;
const CharacterInfoSheet({
super.key,
required this.entityType,
required this.entityId,
required this.character,
});
static Future<bool?> show(
BuildContext context, {
required String entityType,
required String entityId,
required dynamic character,
}) {
return showModalBottomSheet<bool>(
context: context,
backgroundColor: Theme.of(context).colorScheme.surface,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (_) => CharacterInfoSheet(
entityType: entityType,
entityId: entityId,
character: character,
),
);
}
@override
State<CharacterInfoSheet> createState() => _CharacterInfoSheetState();
}
class _CharacterInfoSheetState extends State<CharacterInfoSheet> {
bool _summaryExpanded = false;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final c = widget.character;
final name = c.name as String;
final role = c.role as String?;
final aliases = c.aliases as List<String>;
final tags = c.tags as List<String>;
final description = c.description as String?;
final imagePath = c.imagePath as String?;
final maxHeight = MediaQuery.of(context).size.height * 0.7;
return SafeArea(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: maxHeight),
child: Padding(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 拖拽条
Center(
child: Container(
width: 32,
height: 3,
decoration: BoxDecoration(
color: colors.onSurface.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(2),
),
),
),
const SizedBox(height: 12),
_buildHeader(name, role, imagePath, colors),
const SizedBox(height: 16),
Flexible(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (aliases.isNotEmpty)
_buildInfoRow('别名', aliases.join(''), colors),
if (tags.isNotEmpty)
_buildInfoRow('标签', tags.join(' | '), colors),
if (description != null && description.isNotEmpty) ...[
const SizedBox(height: 12),
_buildSectionTitle('简介', colors),
const SizedBox(height: 8),
_buildSummary(description, colors),
],
],
),
),
),
],
),
),
),
);
}
Widget _buildHeader(String name, String? role, String? imagePath, ColorScheme colors) {
final hasImage = imagePath != null && imagePath.isNotEmpty;
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
shape: BoxShape.circle,
),
clipBehavior: Clip.antiAlias,
child: hasImage
? FadeInLocalImage(path: imagePath, fit: BoxFit.cover)
: Center(
child: Text(
name.isNotEmpty ? name.characters.first : '?',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w600,
color: colors.onSurface.withValues(alpha: 0.3),
),
),
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
name,
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: colors.onSurface),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (role != null && role.isNotEmpty) ...[
const SizedBox(height: 3),
Text(
role,
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.5)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
TextButton.icon(
onPressed: () async {
final result = await Navigator.push<bool>(
context,
MaterialPageRoute(
builder: (_) => CharacterFormPage(
entityType: widget.entityType,
entityId: widget.entityId,
character: widget.character,
),
),
);
if (result == true && mounted) {
Navigator.pop(context, true);
}
},
icon: const Icon(Icons.edit_outlined, size: 16),
label: const Text('编辑', style: TextStyle(fontSize: 13)),
style: TextButton.styleFrom(
foregroundColor: colors.primary,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
minimumSize: const Size(0, 0),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
),
],
);
}
Widget _buildSectionTitle(String title, ColorScheme colors) {
return Row(
children: [
Container(
width: 4,
height: 14,
decoration: BoxDecoration(color: colors.onSurface, borderRadius: BorderRadius.circular(2)),
),
const SizedBox(width: 8),
Text(title, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface)),
],
);
}
Widget _buildInfoRow(String label, String value, ColorScheme colors) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 56,
child: Text(label, style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
),
Expanded(
child: Text(value, style: TextStyle(fontSize: 14, color: colors.onSurface, height: 1.5)),
),
],
),
);
}
Widget _buildSummary(String summary, ColorScheme colors) {
const int previewLimit = 80;
final needsToggle = summary.length > previewLimit;
final displayText = _summaryExpanded || !needsToggle
? summary
: '${summary.substring(0, previewLimit)}';
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(displayText, style: TextStyle(fontSize: 14, color: colors.onSurface, height: 1.7)),
if (needsToggle) ...[
const SizedBox(height: 4),
GestureDetector(
onTap: () => setState(() => _summaryExpanded = !_summaryExpanded),
child: Text(
_summaryExpanded ? '收起' : '展开',
style: TextStyle(fontSize: 12, color: colors.primary),
),
),
],
],
);
}
}

View File

@@ -0,0 +1,226 @@
import 'package:flutter/material.dart';
import 'fade_in_local_image.dart';
/// 角色卡片横向预览组件
///
/// 在影视/书籍/游戏详情页的角色入口上方展示。
/// 空列表返回 SizedBox.shrink(),不占空间。
class CharacterPreviewSection extends StatelessWidget {
final List<dynamic> characters;
final void Function(dynamic character) onTap;
final bool isOverlay;
const CharacterPreviewSection({
super.key,
required this.characters,
required this.onTap,
this.isOverlay = false,
});
@override
Widget build(BuildContext context) {
if (characters.isEmpty) return const SizedBox.shrink();
final colors = Theme.of(context).colorScheme;
final titleColor = isOverlay ? Colors.white : colors.onSurface;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 4,
height: 16,
decoration: BoxDecoration(
color: titleColor,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 8),
Text(
'角色',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: titleColor,
),
),
],
),
const SizedBox(height: 20),
ShaderMask(
shaderCallback: (Rect bounds) {
return const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0x00FFFFFF),
Color(0xFFFFFFFF),
Color(0xFFFFFFFF),
Color(0x00FFFFFF),
],
stops: [0.0, 0.04, 0.96, 1.0],
).createShader(bounds);
},
blendMode: BlendMode.dstIn,
child: SizedBox(
height: 132,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.zero,
itemCount: characters.length,
separatorBuilder: (_, __) => const SizedBox(width: 10),
itemBuilder: (context, index) {
return _CharacterCard(
character: characters[index],
onTap: () => onTap(characters[index]),
isOverlay: isOverlay,
);
},
),
),
),
],
),
);
}
}
class _CharacterCard extends StatelessWidget {
final dynamic character;
final VoidCallback onTap;
final bool isOverlay;
const _CharacterCard({
required this.character,
required this.onTap,
required this.isOverlay,
});
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final name = character.name as String;
final role = character.role as String?;
final aliases = character.aliases as List<String>;
final tags = character.tags as List<String>;
final description = character.description as String?;
final imagePath = character.imagePath as String?;
final cardColor = isOverlay
? Colors.white.withValues(alpha: 0.08)
: colors.surfaceContainerHigh;
final borderColor = isOverlay
? Colors.white.withValues(alpha: 0.12)
: colors.outlineVariant;
final primaryText = isOverlay ? Colors.white : colors.onSurface;
final secondaryText = isOverlay
? Colors.white.withValues(alpha: 0.5)
: colors.onSurface.withValues(alpha: 0.4);
final tagText = isOverlay
? Colors.white.withValues(alpha: 0.7)
: colors.onSurface.withValues(alpha: 0.6);
final avatarBg = isOverlay
? Colors.white.withValues(alpha: 0.1)
: colors.surfaceContainerHighest;
return GestureDetector(
onTap: onTap,
child: Container(
width: 220,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: cardColor,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: borderColor, width: 0.5),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// 第一行:头像 + 名称 + 角色定位
Row(
children: [
Container(
width: 38,
height: 38,
decoration: BoxDecoration(
color: avatarBg,
shape: BoxShape.circle,
),
clipBehavior: Clip.antiAlias,
child: imagePath != null && imagePath.isNotEmpty
? FadeInLocalImage(path: imagePath, fit: BoxFit.cover)
: Center(
child: Text(
name.isNotEmpty ? name.characters.first : '?',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: secondaryText,
),
),
),
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: primaryText,
),
),
if (role != null && role.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 1),
child: Text(
role,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 11, color: secondaryText),
),
),
],
),
),
],
),
// 第二行:标签用 | 分割
if (tags.isNotEmpty || aliases.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
[...tags, ...aliases].join(' | '),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 11, color: tagText, height: 1.3),
),
),
// 第三行:简介,最多两行
if (description != null && description.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text(
description,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 11, color: secondaryText, height: 1.35),
),
),
],
),
),
);
}
}

View File

@@ -1,3 +1,4 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/data_models.dart';
@@ -88,8 +89,14 @@ class _WorkPeopleSectionState extends State<WorkPeopleSection> {
break;
}
// 按 sortOrder 保留首次出现的顺序
final items = byPerson.values.toList();
// 按角色权重排序:导演/编剧/作者等优先,纯演员最后
// 每个人取其所有角色中的最小权重(最高优先级)作为排序依据
final items = byPerson.values.toList()
..sort((a, b) {
final aWeight = a.roleTypes.map(_roleWeight).reduce(min);
final bWeight = b.roleTypes.map(_roleWeight).reduce(min);
return aWeight.compareTo(bWeight);
});
if (!mounted) return;
setState(() {
_items = items;
@@ -182,16 +189,32 @@ class _WorkPeopleSectionState extends State<WorkPeopleSection> {
],
),
const SizedBox(height: 20),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _items.map((item) {
final idx = _items.indexOf(item);
return Padding(
padding: EdgeInsets.only(left: idx == 0 ? 0 : 16),
child: _buildPersonChip(item, colors),
);
}).toList(),
ShaderMask(
shaderCallback: (Rect bounds) {
return const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0x00FFFFFF),
Color(0xFFFFFFFF),
Color(0xFFFFFFFF),
Color(0x00FFFFFF),
],
stops: [0.0, 0.04, 0.96, 1.0],
).createShader(bounds);
},
blendMode: BlendMode.dstIn,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _items.map((item) {
final idx = _items.indexOf(item);
return Padding(
padding: EdgeInsets.only(left: idx == 0 ? 0 : 16),
child: _buildPersonChip(item, colors),
);
}).toList(),
),
),
),
],