feat: rediriger vers l'onglet Statistiques a la fin d'une session
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ class BullyApp extends StatelessWidget {
|
|||||||
Locale('fr', 'FR'), // Français
|
Locale('fr', 'FR'), // Français
|
||||||
],
|
],
|
||||||
locale: const Locale('fr', 'FR'), // Force l'interface en français
|
locale: const Locale('fr', 'FR'), // Force l'interface en français
|
||||||
home: const MainNavigationHolder(),
|
home: MainNavigationHolder(key: mainNavKey),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import 'dart:math' as math;
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../../main_navigation_holder.dart';
|
||||||
import '../../core/constants/app_constants.dart';
|
import '../../core/constants/app_constants.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../data/models/target_type.dart';
|
import '../../data/models/target_type.dart';
|
||||||
@@ -673,6 +674,8 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
sessionProvider.endSession();
|
sessionProvider.endSession();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
|
// Fin de session : on atterrit sur les statistiques.
|
||||||
|
openMainTab(mainTabStats);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import '../../main_navigation_holder.dart';
|
||||||
import '../../core/constants/app_constants.dart';
|
import '../../core/constants/app_constants.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../data/repositories/session_repository.dart';
|
import '../../data/repositories/session_repository.dart';
|
||||||
@@ -230,6 +231,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
backgroundColor: AppTheme.successColor,
|
backgroundColor: AppTheme.successColor,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
// Fin de session : on bascule sur les statistiques.
|
||||||
|
openMainTab(mainTabStats);
|
||||||
},
|
},
|
||||||
child: const Text('TERMINER', style: TextStyle(color: Colors.redAccent)),
|
child: const Text('TERMINER', style: TextStyle(color: Colors.redAccent)),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -5,6 +5,23 @@ import 'features/statistics/statistics_screen.dart';
|
|||||||
import 'features/garage/weapon_list_screen.dart';
|
import 'features/garage/weapon_list_screen.dart';
|
||||||
import 'core/theme/app_theme.dart';
|
import 'core/theme/app_theme.dart';
|
||||||
|
|
||||||
|
/// Index des onglets de la barre de navigation principale.
|
||||||
|
const int mainTabHome = 0;
|
||||||
|
const int mainTabHistory = 1;
|
||||||
|
const int mainTabStats = 2;
|
||||||
|
const int mainTabGarage = 3;
|
||||||
|
|
||||||
|
/// Clé du holder : permet de piloter l'onglet actif depuis n'importe quel
|
||||||
|
/// écran (ex. fin de session -> onglet Stats).
|
||||||
|
final GlobalKey<State<MainNavigationHolder>> mainNavKey =
|
||||||
|
GlobalKey<State<MainNavigationHolder>>();
|
||||||
|
|
||||||
|
/// Ouvre l'onglet [index] de la navigation principale.
|
||||||
|
void openMainTab(int index) {
|
||||||
|
final state = mainNavKey.currentState;
|
||||||
|
if (state is _MainNavigationHolderState) state.selectTab(index);
|
||||||
|
}
|
||||||
|
|
||||||
class MainNavigationHolder extends StatefulWidget {
|
class MainNavigationHolder extends StatefulWidget {
|
||||||
const MainNavigationHolder({super.key});
|
const MainNavigationHolder({super.key});
|
||||||
|
|
||||||
@@ -21,11 +38,12 @@ class _MainNavigationHolderState extends State<MainNavigationHolder> {
|
|||||||
int _statsTick = 0;
|
int _statsTick = 0;
|
||||||
int _historyTick = 0;
|
int _historyTick = 0;
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
void selectTab(int index) {
|
||||||
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
if (index == 1) _historyTick++;
|
if (index == mainTabHistory) _historyTick++;
|
||||||
if (index == 2) _statsTick++;
|
if (index == mainTabStats) _statsTick++;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +72,7 @@ class _MainNavigationHolderState extends State<MainNavigationHolder> {
|
|||||||
),
|
),
|
||||||
child: BottomNavigationBar(
|
child: BottomNavigationBar(
|
||||||
currentIndex: _selectedIndex,
|
currentIndex: _selectedIndex,
|
||||||
onTap: _onItemTapped,
|
onTap: selectTab,
|
||||||
type: BottomNavigationBarType.fixed,
|
type: BottomNavigationBarType.fixed,
|
||||||
backgroundColor: Theme.of(context).cardColor,
|
backgroundColor: Theme.of(context).cardColor,
|
||||||
selectedItemColor: AppTheme.primaryColor,
|
selectedItemColor: AppTheme.primaryColor,
|
||||||
|
|||||||
Reference in New Issue
Block a user