| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:gobang/controllers/game_controller.dart';
- import 'package:gobang/themes/app_colors.dart';
- /// 悔棋 / 投降 / 重开
- class GameActionBar extends StatelessWidget {
- const GameActionBar({super.key});
- @override
- Widget build(BuildContext context) {
- final c = Get.find<GameController>();
- final isDark = c.themeFactory.value.getTheme().isDark;
- return Row(
- children: [
- Expanded(
- child: _ActionChip(
- label: '悔棋',
- icon: Icons.undo_rounded,
- foreground: isDark ? AppColors.ivory : AppColors.ink,
- background: isDark ? AppColors.darkCard : Colors.white,
- onTap: c.undo,
- ),
- ),
- SizedBox(width: 12.w),
- Expanded(
- child: _ActionChip(
- label: '投降',
- icon: Icons.flag_rounded,
- foreground: AppColors.pumpkin,
- background: isDark ? AppColors.darkCard : Colors.white,
- onTap: c.surrender,
- ),
- ),
- SizedBox(width: 12.w),
- Expanded(
- child: _ActionChip(
- label: '重开',
- icon: Icons.refresh_rounded,
- foreground: AppColors.ivory,
- background: AppColors.ink,
- onTap: c.restart,
- elevated: true,
- ),
- ),
- ],
- );
- }
- }
- class _ActionChip extends StatefulWidget {
- const _ActionChip({
- required this.label,
- required this.icon,
- required this.foreground,
- required this.background,
- required this.onTap,
- this.elevated = false,
- });
- final String label;
- final IconData icon;
- final Color foreground;
- final Color background;
- final VoidCallback onTap;
- final bool elevated;
- @override
- State<_ActionChip> createState() => _ActionChipState();
- }
- class _ActionChipState extends State<_ActionChip> {
- bool _pressed = false;
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onTapDown: (_) => setState(() => _pressed = true),
- onTapUp: (_) => setState(() => _pressed = false),
- onTapCancel: () => setState(() => _pressed = false),
- onTap: widget.onTap,
- child: AnimatedScale(
- scale: _pressed ? 0.96 : 1,
- duration: const Duration(milliseconds: 120),
- child: Container(
- padding: EdgeInsets.symmetric(vertical: 14.h),
- decoration: BoxDecoration(
- color: widget.background,
- borderRadius: BorderRadius.circular(16.r),
- boxShadow: [
- BoxShadow(
- color: AppColors.ink.withValues(
- alpha: widget.elevated ? 0.28 : 0.12,
- ),
- blurRadius: 12,
- offset: const Offset(0, 4),
- ),
- ],
- ),
- child: Column(
- children: [
- Icon(widget.icon, color: widget.foreground, size: 24.sp),
- SizedBox(height: 4.h),
- Text(
- widget.label,
- style: TextStyle(
- color: widget.foreground,
- fontSize: 12.sp,
- fontWeight: FontWeight.w600,
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
|