generated from dellevin/template
104 lines
4.0 KiB
Dart
104 lines
4.0 KiB
Dart
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,
|
|
),
|
|
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,
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|