From 262ce70998fa52dec3120589f51c47e96fb96df4 Mon Sep 17 00:00:00 2001
From: 905086 <k2049@qq.com>
Date: Tue, 03 Nov 2026 17:04:19 +0800
Subject: [PATCH] feat: 完成游戏盒子前后端基础功能开发
---
fluttergamebox/lib/pages/favorites_page.dart | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/fluttergamebox/lib/pages/favorites_page.dart b/fluttergamebox/lib/pages/favorites_page.dart
new file mode 100644
index 0000000..dc7ba78
--- /dev/null
+++ b/fluttergamebox/lib/pages/favorites_page.dart
@@ -0,0 +1,101 @@
+import 'package:flutter/material.dart';
+import 'package:fluttergamebox/api/api_client.dart';
+import 'package:fluttergamebox/api/api_service.dart';
+import 'package:fluttergamebox/common/theme.dart';
+import 'package:fluttergamebox/widgets/game_card.dart';
+
+class FavoritesPage extends StatefulWidget {
+ const FavoritesPage({super.key});
+ @override
+ State<FavoritesPage> createState() => FavoritesPageState();
+}
+
+class FavoritesPageState extends State<FavoritesPage>
+ with AutomaticKeepAliveClientMixin {
+ List<Game> games = [];
+ bool _loading = true;
+
+ @override
+ bool get wantKeepAlive => true;
+
+ @override
+ void initState() {
+ super.initState();
+ _load();
+ }
+
+ Future<void> _load() async {
+ final g = await ApiService.favorites();
+ if (!mounted) return;
+ setState(() {
+ games = g;
+ _loading = false;
+ });
+ }
+
+ /// 供主Shell刷新(切换到收藏页/关闭详情页时重新拉取)
+ void refresh() => _load();
+
+ @override
+ Widget build(BuildContext context) {
+ super.build(context);
+ return Container(
+ color: AppColors.bg,
+ padding: const EdgeInsets.fromLTRB(70, 20, 70, 0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ const Icon(Icons.star, color: AppColors.yellow, size: 18),
+ const SizedBox(width: 8),
+ const Text('我的收藏',
+ style: TextStyle(
+ color: Colors.white,
+ fontSize: 16,
+ fontWeight: FontWeight.w500)),
+ const SizedBox(width: 12),
+ Text('共 ${games.length} 款',
+ style: const TextStyle(
+ color: AppColors.textGray, fontSize: 13)),
+ ],
+ ),
+ const SizedBox(height: 16),
+ Expanded(
+ child: _loading
+ ? const Center(
+ child:
+ CircularProgressIndicator(color: AppColors.accent))
+ : games.isEmpty
+ ? const Center(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(Icons.star_border,
+ size: 56, color: AppColors.textDim),
+ SizedBox(height: 12),
+ Text('暂无收藏游戏',
+ style: TextStyle(
+ color: AppColors.textGray,
+ fontSize: 14)),
+ ],
+ ),
+ )
+ : GridView.builder(
+ padding: const EdgeInsets.only(bottom: 40),
+ gridDelegate:
+ const SliverGridDelegateWithFixedCrossAxisCount(
+ crossAxisCount: 4,
+ mainAxisSpacing: 18,
+ crossAxisSpacing: 16,
+ childAspectRatio: 0.62,
+ ),
+ itemCount: games.length,
+ itemBuilder: (context, i) => GameCard(game: games[i]),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
--
Gitblit v1.10.0