deep link from dead app
This commit is contained in:
@@ -69,6 +69,7 @@ class AppRouter {
|
||||
// 1. CREIAMO LA CHIAVE GLOBALE DEL NAVIGATORE
|
||||
static final GlobalKey<NavigatorState> rootNavigatorKey =
|
||||
GlobalKey<NavigatorState>();
|
||||
static String? pendingRoute;
|
||||
static GoRouter createRouter(SessionCubit sessionCubit) {
|
||||
return GoRouter(
|
||||
navigatorKey: rootNavigatorKey,
|
||||
|
||||
@@ -17,20 +17,20 @@ Future<void> setupInteractedMessage() async {
|
||||
}
|
||||
|
||||
void _handleNotificationTap(RemoteMessage message) {
|
||||
// Verifichiamo che tipo di notifica è e prendiamo l'ID
|
||||
final eventType = message.data['eventType'];
|
||||
final referenceId = message.data['referenceId'];
|
||||
|
||||
if (eventType == 'task_assigned' && referenceId != null) {
|
||||
// Navighiamo verso il form del Task usando la GlobalKey!
|
||||
// Assicuriamoci che il context sia disponibile
|
||||
final routePath = '/tasks/form/$referenceId';
|
||||
final context = AppRouter.rootNavigatorKey.currentContext;
|
||||
|
||||
if (context != null) {
|
||||
// Usiamo .push perché è una rotta di dettaglio fuori dalla shell
|
||||
// Il path è /tasks/form/:id (vedi il tuo AppRouter)
|
||||
context.push('/tasks/form/$referenceId');
|
||||
// Scenario A: App già aperta, naviga all'istante
|
||||
context.push(routePath);
|
||||
} else {
|
||||
debugPrint("Attenzione: Context non trovato per il Deep Link!");
|
||||
// Scenario B: App chiusa. Il contesto non c'è ancora, congeliamo la rotta!
|
||||
debugPrint("App in fase di avvio. Congelo la rotta: $routePath");
|
||||
AppRouter.pendingRoute = routePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/routes/app_router.dart';
|
||||
import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
@@ -35,6 +36,18 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (AppRouter.pendingRoute != null) {
|
||||
final destination = AppRouter.pendingRoute!;
|
||||
|
||||
// ⚠️ Svuota IMMEDIATAMENTE la variabile per evitare loop infiniti se si ruota lo schermo!
|
||||
AppRouter.pendingRoute = null;
|
||||
|
||||
// Spedisci l'utente al task!
|
||||
context.push(destination);
|
||||
}
|
||||
});
|
||||
|
||||
// Inizializziamo il sensore del ciclo di vita
|
||||
_lifecycleListener = AppLifecycleListener(
|
||||
onPause: () {
|
||||
|
||||
@@ -90,7 +90,7 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: list.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 12),
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 6),
|
||||
itemBuilder: (context, index) {
|
||||
return _buildStaffCard(list[index]);
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: flux
|
||||
description: "Gestione attività negozio di telefonia"
|
||||
publish_to: 'none'
|
||||
version: 1.1.7+25
|
||||
version: 1.1.8+26
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.3
|
||||
|
||||
Reference in New Issue
Block a user