main_menu.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import 'package:flutter/material.dart';
  2. import 'package:vibration/vibration.dart';
  3. import '../utils/colors.dart';
  4. import '../utils/settings_manager.dart';
  5. import 'game_screen.dart';
  6. import 'settings_screen.dart';
  7. import 'components/animated_background.dart';
  8. import 'components/tutorial_overlay.dart';
  9. class MainMenu extends StatefulWidget {
  10. const MainMenu({super.key});
  11. @override
  12. State<MainMenu> createState() => _MainMenuState();
  13. }
  14. class _MainMenuState extends State<MainMenu> {
  15. bool _showTutorial = false;
  16. @override
  17. void initState() {
  18. super.initState();
  19. _checkTutorial();
  20. }
  21. void _checkTutorial() {
  22. WidgetsBinding.instance.addPostFrameCallback((_) {
  23. if (!SettingsManager.isTutorialShown) {
  24. setState(() {
  25. _showTutorial = true;
  26. });
  27. }
  28. });
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return Scaffold(
  33. backgroundColor: ZenColors.appBackground,
  34. body: AnimatedBackground(
  35. child: Stack(
  36. children: [
  37. SafeArea(
  38. child: Padding(
  39. padding: const EdgeInsets.all(20.0),
  40. child: Column(
  41. children: [
  42. // Header with settings button
  43. Row(
  44. mainAxisAlignment: MainAxisAlignment.end,
  45. children: [
  46. IconButton(
  47. onPressed: _openSettings,
  48. icon: const Icon(
  49. Icons.settings,
  50. color: ZenColors.primaryText,
  51. size: 28,
  52. ),
  53. style: IconButton.styleFrom(
  54. backgroundColor: ZenColors.black.withValues(alpha: 0.3),
  55. shape: const CircleBorder(),
  56. ),
  57. ),
  58. ],
  59. ),
  60. // Main content
  61. Expanded(
  62. child: Column(
  63. mainAxisAlignment: MainAxisAlignment.center,
  64. children: [
  65. // Game Title
  66. const Text(
  67. 'ZenTap',
  68. style: TextStyle(
  69. color: ZenColors.primaryText,
  70. fontSize: 48,
  71. fontWeight: FontWeight.bold,
  72. letterSpacing: 2.0,
  73. ),
  74. ),
  75. const SizedBox(height: 10),
  76. // Subtitle
  77. Text(
  78. 'A stress relief tapping game',
  79. style: TextStyle(
  80. color: ZenColors.secondaryText,
  81. fontSize: 18,
  82. fontStyle: FontStyle.italic,
  83. ),
  84. ),
  85. const SizedBox(height: 60),
  86. // Play Button
  87. _buildMenuButton(
  88. context,
  89. 'Play',
  90. 'Tap to earn Relaxation Points',
  91. Icons.play_arrow,
  92. () => _navigateToGame(context, false),
  93. ),
  94. const SizedBox(height: 20),
  95. // Zen Mode Button
  96. _buildMenuButton(
  97. context,
  98. 'Zen Mode',
  99. 'Pure relaxation, no score',
  100. Icons.self_improvement,
  101. () => _navigateToGame(context, true),
  102. ),
  103. const SizedBox(height: 40),
  104. // Settings hint
  105. Text(
  106. 'Tap anywhere to feel the calm',
  107. style: TextStyle(
  108. color: ZenColors.mutedText,
  109. fontSize: 14,
  110. ),
  111. ),
  112. ],
  113. ),
  114. ),
  115. ],
  116. ),
  117. ),
  118. ),
  119. // Tutorial overlay
  120. if (_showTutorial)
  121. TutorialOverlay(
  122. onComplete: () {
  123. setState(() {
  124. _showTutorial = false;
  125. });
  126. },
  127. ),
  128. ],
  129. ),
  130. ),
  131. );
  132. }
  133. Widget _buildMenuButton(
  134. BuildContext context,
  135. String title,
  136. String subtitle,
  137. IconData icon,
  138. VoidCallback onPressed,
  139. ) {
  140. return Container(
  141. width: double.infinity,
  142. margin: const EdgeInsets.symmetric(horizontal: 20),
  143. child: ElevatedButton(
  144. onPressed: onPressed,
  145. style: ElevatedButton.styleFrom(
  146. backgroundColor: ZenColors.buttonBackground,
  147. foregroundColor: ZenColors.buttonText,
  148. padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 30),
  149. shape: RoundedRectangleBorder(
  150. borderRadius: BorderRadius.circular(15),
  151. ),
  152. elevation: 8,
  153. ),
  154. child: Row(
  155. children: [
  156. Icon(
  157. icon,
  158. size: 32,
  159. color: ZenColors.buttonText,
  160. ),
  161. const SizedBox(width: 20),
  162. Expanded(
  163. child: Column(
  164. crossAxisAlignment: CrossAxisAlignment.start,
  165. children: [
  166. Text(
  167. title,
  168. style: const TextStyle(
  169. fontSize: 22,
  170. fontWeight: FontWeight.bold,
  171. color: ZenColors.buttonText,
  172. ),
  173. ),
  174. const SizedBox(height: 4),
  175. Text(
  176. subtitle,
  177. style: TextStyle(
  178. fontSize: 14,
  179. color: ZenColors.buttonText.withValues(alpha: 0.8),
  180. ),
  181. ),
  182. ],
  183. ),
  184. ),
  185. Icon(
  186. Icons.arrow_forward_ios,
  187. color: ZenColors.buttonText.withValues(alpha: 0.7),
  188. size: 20,
  189. ),
  190. ],
  191. ),
  192. ),
  193. );
  194. }
  195. void _openSettings() async {
  196. if (SettingsManager.isHapticsEnabled) {
  197. try {
  198. await Vibration.vibrate(duration: 50);
  199. } catch (e) {
  200. // Vibration not supported on this platform
  201. }
  202. }
  203. Navigator.of(context).push(
  204. MaterialPageRoute(
  205. builder: (context) => const SettingsScreen(),
  206. ),
  207. );
  208. }
  209. void _navigateToGame(BuildContext context, bool isZenMode) async {
  210. if (SettingsManager.isHapticsEnabled) {
  211. try {
  212. await Vibration.vibrate(duration: 50);
  213. } catch (e) {
  214. // Vibration not supported on this platform
  215. }
  216. }
  217. Navigator.of(context).push(
  218. MaterialPageRoute(
  219. builder: (context) => GameScreen(isZenMode: isZenMode),
  220. ),
  221. );
  222. }
  223. }