Pārlūkot izejas kodu

Fix build errors and warnings

- Remove unused import from audio_manager.dart
- Remove unused variable from score_manager.dart
- Replace deprecated withOpacity() with withValues(alpha:) across UI components
- Add proper mounted checks for BuildContext usage across async gaps
- Replace Container with SizedBox for layout whitespace in stats_screen.dart

All critical build errors have been resolved and the app now builds successfully.
Fszontagh 9 mēneši atpakaļ
vecāks
revīzija
10c0385ea7

+ 0 - 1
lib/game/audio/audio_manager.dart

@@ -1,4 +1,3 @@
-import 'package:flutter/foundation.dart';
 import 'package:flutter/services.dart';
 import 'package:flame_audio/flame_audio.dart';
 import 'dart:math';

+ 1 - 1
lib/ui/components/tutorial_overlay.dart

@@ -93,7 +93,7 @@ class _TutorialOverlayState extends State<TutorialOverlay>
     return FadeTransition(
       opacity: _fadeAnimation,
       child: Container(
-        color: ZenColors.black.withOpacity(0.85),
+        color: ZenColors.black.withValues(alpha: 0.85),
         child: SafeArea(
           child: Stack(
             children: [

+ 2 - 0
lib/ui/game_screen.dart

@@ -355,6 +355,8 @@ class _GameScreenState extends State<GameScreen> {
       await HapticUtils.vibrate(duration: 50);
     }
     
+    if (!mounted) return;
+    
     showDialog(
       context: context,
       builder: (BuildContext context) {

+ 6 - 0
lib/ui/google_play_games_widget.dart

@@ -171,6 +171,8 @@ class _GooglePlayGamesWidgetState extends State<GooglePlayGamesWidget> {
 
     try {
       final success = await _gamesManager.signIn();
+      if (!mounted) return;
+      
       if (success) {
         ScaffoldMessenger.of(context).showSnackBar(
           const SnackBar(
@@ -187,6 +189,7 @@ class _GooglePlayGamesWidgetState extends State<GooglePlayGamesWidget> {
         );
       }
     } catch (e) {
+      if (!mounted) return;
       ScaffoldMessenger.of(context).showSnackBar(
         SnackBar(
           content: Text('Error signing in: $e'),
@@ -204,6 +207,7 @@ class _GooglePlayGamesWidgetState extends State<GooglePlayGamesWidget> {
 
   Future<void> _signOut() async {
     await _gamesManager.signOut();
+    if (!mounted) return;
     setState(() {});
     
     ScaffoldMessenger.of(context).showSnackBar(
@@ -218,6 +222,7 @@ class _GooglePlayGamesWidgetState extends State<GooglePlayGamesWidget> {
     try {
       await _gamesManager.showLeaderboards();
     } catch (e) {
+      if (!mounted) return;
       ScaffoldMessenger.of(context).showSnackBar(
         SnackBar(
           content: Text('Error showing leaderboards: $e'),
@@ -231,6 +236,7 @@ class _GooglePlayGamesWidgetState extends State<GooglePlayGamesWidget> {
     try {
       await _gamesManager.showAchievements();
     } catch (e) {
+      if (!mounted) return;
       ScaffoldMessenger.of(context).showSnackBar(
         SnackBar(
           content: Text('Error showing achievements: $e'),

+ 5 - 2
lib/ui/main_menu.dart

@@ -492,6 +492,7 @@ class _MainMenuState extends State<MainMenu> {
       await HapticUtils.vibrate(duration: 50);
     }
     
+    if (!mounted) return;
     Navigator.of(context).push(
       MaterialPageRoute(
         builder: (context) => const SettingsScreen(),
@@ -504,6 +505,7 @@ class _MainMenuState extends State<MainMenu> {
       await HapticUtils.vibrate(duration: 50);
     }
     
+    if (!mounted) return;
     final result = await Navigator.of(context).push(
       MaterialPageRoute(
         builder: (context) => const StatsScreen(),
@@ -516,11 +518,12 @@ class _MainMenuState extends State<MainMenu> {
     }
   }
 
-  void _navigateToGame(BuildContext context, bool isZenMode) async {
+  void _navigateToGame(BuildContext ctx, bool isZenMode) async {
     if (SettingsManager.isHapticsEnabled) {
       await HapticUtils.vibrate(duration: 50);
     }
     
+    if (!mounted) return;
     final result = await Navigator.of(context).push(
       MaterialPageRoute(
         builder: (context) => GameScreen(isZenMode: isZenMode),
@@ -528,7 +531,7 @@ class _MainMenuState extends State<MainMenu> {
     );
     
     // Refresh score when returning from game
-    if (result == true) {
+    if (mounted && result == true) {
       _loadTodayScore();
     }
   }

+ 10 - 10
lib/ui/settings_screen.dart

@@ -54,7 +54,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
                         size: 28,
                       ),
                       style: IconButton.styleFrom(
-                        backgroundColor: ZenColors.black.withOpacity(0.3),
+                        backgroundColor: ZenColors.black.withValues(alpha: 0.3),
                         shape: const CircleBorder(),
                       ),
                     ),
@@ -197,10 +197,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
       margin: const EdgeInsets.only(top: 12),
       padding: const EdgeInsets.all(16),
       decoration: BoxDecoration(
-        color: ZenColors.uiElements.withOpacity(0.3),
+        color: ZenColors.uiElements.withValues(alpha: 0.3),
         borderRadius: BorderRadius.circular(12),
         border: Border.all(
-          color: ZenColors.uiElements.withOpacity(0.2),
+          color: ZenColors.uiElements.withValues(alpha: 0.2),
           width: 1,
         ),
       ),
@@ -239,9 +239,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
             value: value,
             onChanged: onChanged,
             activeColor: ZenColors.buttonBackground,
-            activeTrackColor: ZenColors.buttonBackground.withOpacity(0.3),
+            activeTrackColor: ZenColors.buttonBackground.withValues(alpha: 0.3),
             inactiveThumbColor: ZenColors.mutedText,
-            inactiveTrackColor: ZenColors.mutedText.withOpacity(0.2),
+            inactiveTrackColor: ZenColors.mutedText.withValues(alpha: 0.2),
           ),
         ],
       ),
@@ -257,7 +257,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
     return Container(
       margin: const EdgeInsets.only(top: 12),
       child: Material(
-        color: ZenColors.uiElements.withOpacity(0.3),
+        color: ZenColors.uiElements.withValues(alpha: 0.3),
         borderRadius: BorderRadius.circular(12),
         child: InkWell(
           onTap: onTap,
@@ -267,7 +267,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
             decoration: BoxDecoration(
               borderRadius: BorderRadius.circular(12),
               border: Border.all(
-                color: ZenColors.uiElements.withOpacity(0.2),
+                color: ZenColors.uiElements.withValues(alpha: 0.2),
                 width: 1,
               ),
             ),
@@ -429,10 +429,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
       margin: const EdgeInsets.only(top: 8),
       padding: const EdgeInsets.all(16),
       decoration: BoxDecoration(
-        color: ZenColors.uiElements.withOpacity(0.3),
+        color: ZenColors.uiElements.withValues(alpha: 0.3),
         borderRadius: BorderRadius.circular(12),
         border: Border.all(
-          color: ZenColors.uiElements.withOpacity(0.2),
+          color: ZenColors.uiElements.withValues(alpha: 0.2),
           width: 1,
         ),
       ),
@@ -465,7 +465,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
                   divisions: 10,
                   label: '${(value * 100).round()}%',
                   activeColor: ZenColors.buttonBackground,
-                  inactiveColor: ZenColors.mutedText.withOpacity(0.2),
+                  inactiveColor: ZenColors.mutedText.withValues(alpha: 0.2),
                 ),
               ],
             ),

+ 1 - 1
lib/ui/stats_screen.dart

@@ -226,7 +226,7 @@ class _StatsScreenState extends State<StatsScreen> with TickerProviderStateMixin
           ),
         ),
         const SizedBox(height: 15),
-        Container(
+        SizedBox(
           height: 120,
           child: ListView.builder(
             scrollDirection: Axis.horizontal,

+ 0 - 1
lib/utils/score_manager.dart

@@ -56,7 +56,6 @@ class ScoreManager {
 
     for (int i = weeks - 1; i >= 0; i--) {
       final weekStart = now.subtract(Duration(days: now.weekday - 1 + (i * 7)));
-      final weekEnd = weekStart.add(const Duration(days: 6));
       
       int weekTotal = 0;
       for (int day = 0; day < 7; day++) {