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/tools_page.dart |  244 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 244 insertions(+), 0 deletions(-)

diff --git a/fluttergamebox/lib/pages/tools_page.dart b/fluttergamebox/lib/pages/tools_page.dart
new file mode 100644
index 0000000..81d01d4
--- /dev/null
+++ b/fluttergamebox/lib/pages/tools_page.dart
@@ -0,0 +1,244 @@
+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/store/app_state.dart';
+import 'package:fluttergamebox/utils/util.dart';
+import 'package:fluttergamebox/widgets/download_manager.dart';
+
+class ToolsPage extends StatefulWidget {
+  const ToolsPage({super.key});
+  @override
+  State<ToolsPage> createState() => _ToolsPageState();
+}
+
+class _ToolsPageState extends State<ToolsPage>
+    with AutomaticKeepAliveClientMixin {
+  List<Tool> tools = [];
+  final Set<int> _installed = {};
+  bool _loading = true;
+
+  @override
+  bool get wantKeepAlive => true;
+
+  @override
+  void initState() {
+    super.initState();
+    _load();
+  }
+
+  Future<void> _load() async {
+    final t = await ApiService.tools();
+    if (!mounted) return;
+    setState(() {
+      tools = t;
+      _loading = false;
+    });
+  }
+
+  Future<void> _install(Tool tool) async {
+    if (_installed.contains(tool.id)) return;
+    // 模拟安装
+    setState(() => _installed.add(tool.id));
+    _toast('${tool.name} 安装完成');
+  }
+
+  void _toast(String msg) {
+    final overlay = Overlay.of(context);
+    final entry = OverlayEntry(
+      builder: (context) => Positioned(
+        top: 60,
+        left: MediaQuery.of(context).size.width / 2 - 140,
+        child: Material(
+          color: Colors.transparent,
+          child: Container(
+            width: 280,
+            padding:
+                const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
+            decoration: BoxDecoration(
+              color: AppColors.green,
+              borderRadius: BorderRadius.circular(6),
+            ),
+            child: Row(
+              children: [
+                const Icon(Icons.check_circle,
+                    color: Colors.white, size: 18),
+                const SizedBox(width: 8),
+                Expanded(
+                  child: Text(msg,
+                      style: const TextStyle(
+                          color: Colors.white, fontSize: 13)),
+                ),
+              ],
+            ),
+          ),
+        ),
+      ),
+    );
+    overlay.insert(entry);
+    Future.delayed(const Duration(seconds: 2), () => entry.remove());
+  }
+
+  @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.build_outlined,
+                  color: AppColors.accent, size: 18),
+              const SizedBox(width: 8),
+              const Text('常用工具',
+                  style: TextStyle(
+                      color: Colors.white,
+                      fontSize: 16,
+                      fontWeight: FontWeight.w500)),
+              const SizedBox(width: 12),
+              const Text('游戏必备运行库和实用工具',
+                  style: TextStyle(
+                      color: AppColors.textGray, fontSize: 13)),
+            ],
+          ),
+          const SizedBox(height: 16),
+          Expanded(
+            child: _loading
+                ? const Center(
+                    child:
+                        CircularProgressIndicator(color: AppColors.accent))
+                : tools.isEmpty
+                    ? const Center(
+                        child: Text('暂无工具',
+                            style:
+                                TextStyle(color: AppColors.textGray)))
+                    : GridView.builder(
+                        padding: const EdgeInsets.only(bottom: 40),
+                        gridDelegate:
+                            const SliverGridDelegateWithFixedCrossAxisCount(
+                          crossAxisCount: 4,
+                          mainAxisSpacing: 18,
+                          crossAxisSpacing: 16,
+                          childAspectRatio: 0.72,
+                        ),
+                        itemCount: tools.length,
+                        itemBuilder: (context, i) =>
+                            _ToolCard(tool: tools[i], installed: _installed.contains(tools[i].id), onInstall: () => _install(tools[i])),
+                      ),
+          ),
+        ],
+      ),
+    );
+  }
+}
+
+class _ToolCard extends StatelessWidget {
+  final Tool tool;
+  final bool installed;
+  final VoidCallback onInstall;
+  const _ToolCard({
+    required this.tool,
+    required this.installed,
+    required this.onInstall,
+  });
+
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      decoration: BoxDecoration(
+        color: AppColors.bgLight,
+        borderRadius: BorderRadius.circular(6),
+      ),
+      child: Column(
+        children: [
+          // 封面
+          Expanded(
+            child: Stack(
+              fit: StackFit.expand,
+              children: [
+                ClipRRect(
+                  borderRadius: const BorderRadius.vertical(
+                      top: Radius.circular(6)),
+                  child: Image.network(
+                    ApiClient.baseUrl + tool.cover,
+                    fit: BoxFit.cover,
+                    errorBuilder: (_, __, ___) => Container(
+                      color: const Color(0xFF2A2E45),
+                      child: Center(
+                        child: Text(
+                          tool.name.characters.first,
+                          style: const TextStyle(
+                              color: AppColors.textDim, fontSize: 28),
+                        ),
+                      ),
+                    ),
+                  ),
+                ),
+                // 常用工具标签
+                Positioned(
+                  left: 0,
+                  top: 8,
+                  child: Container(
+                    padding: const EdgeInsets.symmetric(
+                        horizontal: 8, vertical: 3),
+                    decoration: const BoxDecoration(
+                      color: AppColors.accent,
+                      borderRadius: BorderRadius.horizontal(
+                          right: Radius.circular(3)),
+                    ),
+                    child: const Text('常用工具',
+                        style: TextStyle(
+                            color: Colors.white, fontSize: 11)),
+                  ),
+                ),
+              ],
+            ),
+          ),
+          // 信息
+          Padding(
+            padding: const EdgeInsets.all(10),
+            child: Column(
+              children: [
+                Text(tool.description,
+                    maxLines: 1,
+                    overflow: TextOverflow.ellipsis,
+                    style: const TextStyle(
+                        color: Colors.white, fontSize: 12)),
+                const SizedBox(height: 8),
+                Row(
+                  children: [
+                    Text(tool.size,
+                        style: const TextStyle(
+                            color: AppColors.textDim, fontSize: 11)),
+                    const Spacer(),
+                    GestureDetector(
+                      onTap: onInstall,
+                      child: Container(
+                        padding: const EdgeInsets.symmetric(
+                            horizontal: 14, vertical: 4),
+                        decoration: BoxDecoration(
+                          color: installed
+                              ? const Color(0xFF3A3F52)
+                              : AppColors.accent,
+                          borderRadius: BorderRadius.circular(3),
+                        ),
+                        child: Text(
+                          installed ? '已安装' : '安装',
+                          style: const TextStyle(
+                              color: Colors.white, fontSize: 11),
+                        ),
+                      ),
+                    ),
+                  ],
+                ),
+              ],
+            ),
+          ),
+        ],
+      ),
+    );
+  }
+}

--
Gitblit v1.10.0