新增游戏功能记录模块

This commit is contained in:
DelLevin-Home
2026-07-06 01:33:42 +08:00
parent 0ad3713382
commit 4a7296f00f
32 changed files with 5735 additions and 37 deletions

View File

@@ -20,6 +20,12 @@ void showQuickAddSheet(BuildContext context, AppProvider provider) {
arguments: {'initialStatus': currentStatus});
case 2:
Navigator.pushNamed(context, '/note-form');
case 3:
final statusMap = {0: 'completed', 1: 'playing', 2: 'want_to_play', 3: 'abandoned'};
final currentStatus =
statusMap[provider.gameStatusIndex] ?? 'want_to_play';
Navigator.pushNamed(context, '/game-form',
arguments: {'initialStatus': currentStatus});
default:
showAddSheet(context, provider);
}
@@ -111,6 +117,25 @@ void showAddSheet(BuildContext context, AppProvider provider) {
Navigator.pushNamed(outerContext, '/note-form');
},
),
_buildOption(
colors: bc,
icon: Icons.sports_esports_outlined,
title: '添加游戏',
subtitle: '记录你玩过的游戏',
onTap: () {
Navigator.pop(ctx);
final statusMap = {
0: 'completed',
1: 'playing',
2: 'want_to_play',
3: 'abandoned',
};
final s =
statusMap[provider.gameStatusIndex] ?? 'want_to_play';
Navigator.pushNamed(outerContext, '/game-form',
arguments: {'initialStatus': s});
},
),
],
),
),

View File

@@ -13,6 +13,7 @@ import '../pages/settings/tag_management_page.dart';
import '../pages/movies/movie_detail_page.dart';
import '../pages/book/book_detail_page.dart';
import '../pages/note/note_detail_page.dart';
import '../pages/game/game_detail_page.dart';
import '../models/data_models.dart';
import 'fade_in_local_image.dart';
@@ -32,6 +33,7 @@ class _CustomDrawerState extends State<CustomDrawer> {
List<Movie>? _cachedMovies;
List<Book>? _cachedBooks;
List<Note>? _cachedNotes;
List<Game>? _cachedGames;
Map<DateTime, int>? _cachedDailyCounts;
int? _cachedMaxCount;
@@ -112,6 +114,7 @@ class _CustomDrawerState extends State<CustomDrawer> {
final movieCount = provider.movies.where((m) => !m.isDeleted).length;
final bookCount = provider.books.length;
final noteCount = provider.notes.length;
final gameCount = provider.games.where((g) => !g.isDeleted).length;
return Container(
margin: const EdgeInsets.fromLTRB(16, 16, 16, 0),
@@ -162,6 +165,8 @@ class _CustomDrawerState extends State<CustomDrawer> {
_buildProfileStatRow(Icons.menu_book_outlined, bookCount, '阅读'),
const SizedBox(height: 12),
_buildProfileStatRow(Icons.note_outlined, noteCount, '笔记'),
const SizedBox(height: 12),
_buildProfileStatRow(Icons.sports_esports_outlined, gameCount, '游戏'),
],
),
);
@@ -258,10 +263,11 @@ class _CustomDrawerState extends State<CustomDrawer> {
// ─── 热力图缓存计算 ───
(int, Map<DateTime, int>) _computeDailyCounts(List<Movie> movies, List<Book> books, List<Note> notes) {
(int, Map<DateTime, int>) _computeDailyCounts(List<Movie> movies, List<Book> books, List<Note> notes, List<Game> games) {
if (identical(movies, _cachedMovies) &&
identical(books, _cachedBooks) &&
identical(notes, _cachedNotes) &&
identical(games, _cachedGames) &&
_cachedDailyCounts != null) {
return (_cachedMaxCount!, _cachedDailyCounts!);
}
@@ -279,6 +285,10 @@ class _CustomDrawerState extends State<CustomDrawer> {
final date = DateTime(note.createdAt.year, note.createdAt.month, note.createdAt.day);
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
}
for (final game in games.where((g) => !g.isDeleted)) {
final date = DateTime(game.createdAt.year, game.createdAt.month, game.createdAt.day);
dailyCounts[date] = (dailyCounts[date] ?? 0) + 1;
}
int maxCount = 0;
for (final c in dailyCounts.values) {
@@ -289,15 +299,17 @@ class _CustomDrawerState extends State<CustomDrawer> {
_cachedMovies = movies;
_cachedBooks = books;
_cachedNotes = notes;
_cachedGames = games;
_cachedDailyCounts = dailyCounts;
_cachedMaxCount = maxCount;
return (maxCount, dailyCounts);
}
List<_RecentItem> _computeRecentItems(List<Movie> movies, List<Book> books, List<Note> notes) {
List<_RecentItem> _computeRecentItems(List<Movie> movies, List<Book> books, List<Note> notes, List<Game> games) {
if (identical(movies, _cachedMovies) &&
identical(books, _cachedBooks) &&
identical(notes, _cachedNotes) &&
identical(games, _cachedGames) &&
_cachedRecentItems != null) {
return _cachedRecentItems!;
}
@@ -312,6 +324,9 @@ class _CustomDrawerState extends State<CustomDrawer> {
for (final n in notes.where((n) => !n.isDeleted)) {
items.add(_RecentItem(type: 'note', title: n.title.isNotEmpty ? n.title : '随手记', date: n.createdAt, data: n));
}
for (final g in games.where((g) => !g.isDeleted)) {
items.add(_RecentItem(type: 'game', title: g.title, date: g.createdAt, data: g));
}
items.sort((a, b) => b.date.compareTo(a.date));
_cachedRecentItems = items;
@@ -322,9 +337,10 @@ class _CustomDrawerState extends State<CustomDrawer> {
final movies = context.select<AppProvider, List<Movie>>((p) => p.movies);
final books = context.select<AppProvider, List<Book>>((p) => p.books);
final notes = context.select<AppProvider, List<Note>>((p) => p.notes);
final games = context.select<AppProvider, List<Game>>((p) => p.games);
final colors = Theme.of(context).colorScheme;
final (maxCount, dailyCounts) = _computeDailyCounts(movies, books, notes);
final (maxCount, dailyCounts) = _computeDailyCounts(movies, books, notes, games);
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
@@ -442,8 +458,9 @@ class _CustomDrawerState extends State<CustomDrawer> {
final movies = context.select<AppProvider, List<Movie>>((p) => p.movies);
final books = context.select<AppProvider, List<Book>>((p) => p.books);
final notes = context.select<AppProvider, List<Note>>((p) => p.notes);
final games = context.select<AppProvider, List<Game>>((p) => p.games);
final colors = Theme.of(context).colorScheme;
final recent = _computeRecentItems(movies, books, notes);
final recent = _computeRecentItems(movies, books, notes, games);
if (recent.isEmpty) return const SizedBox.shrink();
return Container(
@@ -469,7 +486,7 @@ class _CustomDrawerState extends State<CustomDrawer> {
child: Row(
children: [
Icon(
item.type == 'movie' ? Icons.movie_outlined : item.type == 'book' ? Icons.menu_book_outlined : Icons.note_outlined,
item.type == 'movie' ? Icons.movie_outlined : item.type == 'book' ? Icons.menu_book_outlined : item.type == 'game' ? Icons.sports_esports_outlined : Icons.note_outlined,
size: 14, color: colors.onSurface.withValues(alpha: 0.3),
),
const SizedBox(width: 10),
@@ -497,6 +514,8 @@ class _CustomDrawerState extends State<CustomDrawer> {
Navigator.push(context, MaterialPageRoute(builder: (_) => BookDetailPage(book: item.data as Book)));
case 'note':
Navigator.push(context, MaterialPageRoute(builder: (_) => NoteDetailPage(note: item.data as Note)));
case 'game':
Navigator.push(context, MaterialPageRoute(builder: (_) => GameDetailPage(game: item.data as Game)));
}
}

View File

@@ -0,0 +1,129 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/data_models.dart';
import '../providers/app_provider.dart';
import '../widgets/fade_in_local_image.dart';
import '../widgets/animated_star_rating.dart';
import '../utils/toast_util.dart';
/// 游戏列表项组件 - 网格布局设计
class GameListItem extends StatelessWidget {
final Game game;
final bool selected;
final VoidCallback? onTap;
const GameListItem({super.key, required this.game, this.selected = false, this.onTap});
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return GestureDetector(
onTap: onTap ?? () => Navigator.pushNamed(context, '/game-detail', arguments: game),
onLongPress: () => _showDeleteDialog(context),
child: Container(
decoration: selected
? BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: colors.primary, width: 2),
)
: null,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: _buildCover(colors),
),
const SizedBox(height: 8),
Text(
game.title,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.onSurface,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
if (game.rating != null)
AnimatedStarRating(rating: game.rating!, starSize: 12, showNumber: true)
else
const SizedBox(height: 16),
],
),
),
);
}
Widget _buildCover(ColorScheme colors) {
return Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
),
clipBehavior: Clip.antiAlias,
child: FadeInLocalImage(
path: game.coverPath,
fit: BoxFit.cover,
placeholder: Center(child: Icon(Icons.sports_esports_outlined, size: 24, color: colors.onSurface.withValues(alpha: 0.25))),
errorWidget: Center(child: Icon(Icons.sports_esports_outlined, size: 24, color: colors.onSurface.withValues(alpha: 0.25))),
),
);
}
void _showDeleteDialog(BuildContext context) {
final colors = Theme.of(context).colorScheme;
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: colors.surface,
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
title: Text(
'确认删除',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: colors.onSurface,
),
),
content: Text(
'确定要删除《${game.title}》吗?删除后可在回收站恢复。',
style: TextStyle(
fontSize: 14,
color: colors.onSurface.withValues(alpha: 0.6),
height: 1.5,
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
style: TextButton.styleFrom(
foregroundColor: colors.onSurface.withValues(alpha: 0.6),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
child: const Text('取消'),
),
ElevatedButton(
onPressed: () async {
await context.read<AppProvider>().removeGame(game.id);
Navigator.pop(context);
ToastUtil.show(context, '已删除');
},
style: ElevatedButton.styleFrom(
backgroundColor: colors.error,
foregroundColor: colors.onError,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
child: const Text('删除'),
),
],
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
),
);
}
}

View File

@@ -0,0 +1,104 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/app_provider.dart';
/// 游戏状态选择栏 - 平滑过渡动画
class GameStatusBar extends StatelessWidget {
const GameStatusBar({super.key});
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Consumer<AppProvider>(
builder: (context, provider, child) {
final currentIndex = provider.gameStatusIndex;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: colors.surface,
border: Border(bottom: BorderSide(color: colors.outline, width: 0.5)),
),
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(24),
),
child: LayoutBuilder(
builder: (context, constraints) {
final tabWidth = constraints.maxWidth / 4;
return SizedBox(
height: 40,
child: Stack(
children: [
AnimatedPositioned(
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
left: currentIndex * tabWidth,
top: 0, bottom: 0, width: tabWidth,
child: Padding(
padding: const EdgeInsets.all(3),
child: Container(
decoration: BoxDecoration(
color: colors.primary,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(color: Colors.black.withValues(alpha: 0.1), blurRadius: 8, offset: const Offset(0, 2)),
],
),
),
),
),
Row(
children: [
_buildTab(colors, '已通关', Icons.emoji_events_outlined, currentIndex == 0,
() => provider.setGameStatusIndex(0)),
_buildTab(colors, '在玩', Icons.sports_esports_outlined, currentIndex == 1,
() => provider.setGameStatusIndex(1)),
_buildTab(colors, '想玩', Icons.bookmark_outlined, currentIndex == 2,
() => provider.setGameStatusIndex(2)),
_buildTab(colors, '弃游', Icons.cancel_outlined, currentIndex == 3,
() => provider.setGameStatusIndex(3)),
],
),
],
),
);
},
),
),
);
},
);
}
Widget _buildTab(ColorScheme colors, String label, IconData icon, bool isSelected, VoidCallback onTap) {
return Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: AnimatedOpacity(
opacity: isSelected ? 1.0 : 0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: SizedBox.expand(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 16, color: isSelected ? colors.onPrimary : colors.onSurface),
const SizedBox(width: 6),
Text(label,
style: TextStyle(
fontSize: 13,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
color: isSelected ? colors.onPrimary : colors.onSurface,
)),
],
),
),
),
),
);
}
}

View File

@@ -140,6 +140,46 @@ class BookSkeletonGrid extends StatelessWidget {
}
}
/// 游戏骨架屏
class GameSkeletonGrid extends StatelessWidget {
const GameSkeletonGrid({super.key});
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final count = responsiveCrossAxisCount(constraints.maxWidth, minItemWidth: 110);
return GridView.builder(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 100),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: count,
childAspectRatio: 0.55,
crossAxisSpacing: 12,
mainAxisSpacing: 16,
),
itemCount: count * 3,
itemBuilder: (_, __) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: ShimmerSkeleton(
width: double.infinity,
height: double.infinity,
borderRadius: 8,
),
),
const SizedBox(height: 8),
const ShimmerSkeleton(width: double.infinity, height: 14),
const SizedBox(height: 4),
const ShimmerSkeleton(width: 70, height: 12),
],
),
);
},
);
}
}
/// 笔记列表骨架屏
class NoteSkeletonList extends StatelessWidget {
const NoteSkeletonList({super.key});