新增影视的字段

This commit is contained in:
DelLevin-Home
2026-03-05 10:40:42 +08:00
parent adad6372a3
commit 44e5418031
10 changed files with 2440 additions and 592 deletions

View File

@@ -1,3 +1,4 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/app_provider.dart';
@@ -12,11 +13,21 @@ class MovieListItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
return Card(
margin: const EdgeInsets.only(bottom: 12),
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
color: colorScheme.outline.withOpacity(0.1),
width: 1,
),
),
child: InkWell(
onTap: () {
// 跳转到详情页
Navigator.pushNamed(context, '/movie-detail', arguments: movie);
},
borderRadius: BorderRadius.circular(12),
@@ -25,103 +36,126 @@ class MovieListItem extends StatelessWidget {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 海报占位图
_buildPoster(),
// 海报
_buildPoster(context),
const SizedBox(width: 12),
const SizedBox(width: 14),
// 影片信息
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题和年份
// 标题
Text(
movie.title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: colorScheme.onSurface,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (movie.year != null) ...[
const SizedBox(height: 4),
Text(
'${movie.year}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
const SizedBox(height: 6),
const SizedBox(height: 8),
// 评分和状态
// 上映日期和评分
Row(
children: [
if (movie.rating != null) ...[
if (movie.releaseDate != null) ...[
Icon(
Icons.star,
size: 16,
color: Colors.amber[700],
Icons.calendar_today_outlined,
size: 13,
color: colorScheme.onSurfaceVariant.withOpacity(0.7),
),
const SizedBox(width: 4),
Text(
movie.rating.toString(),
'${movie.releaseDate!.year}',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.amber[700],
fontSize: 13,
color: colorScheme.onSurfaceVariant.withOpacity(0.7),
),
),
const SizedBox(width: 12),
],
// 状态标签
_buildStatusTag(context),
if (movie.rating != null) ...[
Icon(
Icons.star_rounded,
size: 14,
color: Colors.amber[700],
),
const SizedBox(width: 2),
Text(
movie.rating!.toStringAsFixed(1),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Colors.amber[700],
),
),
],
],
),
if (movie.watchDate != null) ...[
const SizedBox(height: 6),
Text(
'观看日期:${_formatDate(movie.watchDate!)}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
const SizedBox(height: 8),
if (movie.note != null && movie.note!.isNotEmpty) ...[
const SizedBox(height: 6),
Text(
movie.note!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
// 导演
if (movie.directors.isNotEmpty)
_buildInfoRow(
context,
prefix: '导演',
items: movie.directors.take(2).toList(),
),
],
if (movie.directors.isNotEmpty && movie.genres.isNotEmpty)
const SizedBox(height: 4),
// 类型标签
if (movie.genres.isNotEmpty)
Wrap(
spacing: 6,
runSpacing: 4,
children: movie.genres.take(3).map((genre) => Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: colorScheme.primary.withOpacity(0.08),
borderRadius: BorderRadius.circular(4),
),
child: Text(
genre,
style: TextStyle(
fontSize: 11,
color: colorScheme.primary.withOpacity(0.8),
),
),
)).toList(),
),
const SizedBox(height: 8),
// 状态标签
_buildStatusTag(context),
],
),
),
// 右侧操作按钮
Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.edit, size: 20),
icon: Icon(Icons.edit_outlined, size: 20, color: colorScheme.primary),
onPressed: () {
Navigator.pushNamed(context, '/movie-form', arguments: movie);
},
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
),
const SizedBox(height: 8),
IconButton(
icon: const Icon(Icons.delete_outline, size: 20),
color: Colors.red,
icon: Icon(Icons.delete_outline, size: 20, color: colorScheme.error.withOpacity(0.7)),
onPressed: () => _showDeleteDialog(context, movie),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
@@ -135,23 +169,65 @@ class MovieListItem extends StatelessWidget {
);
}
/// 构建海报占位图
Widget _buildPoster() {
return Container(
width: 60,
height: 90,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(8),
/// 构建海报
Widget _buildPoster(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Container(
width: 70,
height: 100,
color: colorScheme.surfaceContainerHighest,
child: movie.posterPath != null && movie.posterPath!.isNotEmpty
? Image.file(
File(movie.posterPath!),
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) => _buildPlaceholder(context),
)
: _buildPlaceholder(context),
),
);
}
Widget _buildPlaceholder(BuildContext context) {
return Center(
child: Icon(
Icons.movie,
color: Colors.grey[500],
size: 32,
Icons.movie_outlined,
color: Theme.of(context).colorScheme.onSurfaceVariant.withOpacity(0.3),
size: 28,
),
);
}
/// 构建信息行
Widget _buildInfoRow(BuildContext context, {required String prefix, required List<String> items}) {
final colorScheme = Theme.of(context).colorScheme;
return Row(
children: [
Text(
'$prefix: ',
style: TextStyle(
fontSize: 12,
color: colorScheme.onSurfaceVariant.withOpacity(0.6),
),
),
Expanded(
child: Text(
items.join(' / '),
style: TextStyle(
fontSize: 12,
color: colorScheme.onSurfaceVariant.withOpacity(0.8),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
);
}
/// 构建状态标签
Widget _buildStatusTag(BuildContext context) {
Color statusColor;
@@ -176,12 +252,12 @@ class MovieListItem extends StatelessWidget {
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: statusColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
border: Border.all(
color: statusColor,
color: statusColor.withOpacity(0.3),
width: 1,
),
),
@@ -190,28 +266,36 @@ class MovieListItem extends StatelessWidget {
style: TextStyle(
fontSize: 11,
color: statusColor,
fontWeight: FontWeight.bold,
fontWeight: FontWeight.w600,
),
),
);
}
/// 格式化日期
String _formatDate(DateTime date) {
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
}
/// 显示删除对话框
void _showDeleteDialog(BuildContext context, Movie movie) {
final colorScheme = Theme.of(context).colorScheme;
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('确认删除'),
content: Text('确定要删除"${movie.title}"吗?此操作不可恢复。'),
backgroundColor: colorScheme.surface,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
title: Text(
'确认删除',
style: TextStyle(color: colorScheme.onSurface),
),
content: Text(
'确定要删除"${movie.title}"吗?',
style: TextStyle(color: colorScheme.onSurface.withOpacity(0.7)),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
child: Text(
'取消',
style: TextStyle(color: colorScheme.onSurfaceVariant),
),
),
TextButton(
onPressed: () async {
@@ -219,15 +303,16 @@ class MovieListItem extends StatelessWidget {
if (!context.mounted) return;
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('已删除'),
SnackBar(
content: const Text('已删除'),
behavior: SnackBarBehavior.floating,
backgroundColor: colorScheme.primary,
),
);
},
child: const Text(
child: Text(
'删除',
style: TextStyle(color: Colors.red),
style: TextStyle(color: colorScheme.error),
),
),
],