uodate
This commit is contained in:
+22
-27
@@ -1,4 +1,4 @@
|
||||
import 'package:animated_splash_screen/animated_splash_screen.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -40,7 +40,7 @@ void main() async {
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
).then((value) => Get.put(AuthenticationRepository()));
|
||||
|
||||
FirebaseMessaging.onBackgroundMessage((message) => _firebaseMessagingBackgroundHandler(message, context)); // Pasa el contexto aquí
|
||||
FirebaseMessaging.onBackgroundMessage((_firebaseMessagingBackgroundHandler));
|
||||
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
@@ -54,14 +54,27 @@ void main() async {
|
||||
sound: true,
|
||||
);
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
print('Got a message whilst in the foreground!');
|
||||
print('Message data: ${message.data}');
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
print('Got a message whilst in the foreground!');
|
||||
print('Message data: ${message.data}');
|
||||
|
||||
// Obtener el valor de la clave "screen" de los datos de la notificación
|
||||
String? notificationScreen = message.data['screen'];
|
||||
|
||||
// Navegar a la pantalla correspondiente según el valor de la clave "screen"
|
||||
if (notificationScreen == "misservicios") {
|
||||
// Navegar a MyServicesScreen
|
||||
Get.offNamed('/misservicios');
|
||||
} else if (notificationScreen == "solicitud") {
|
||||
// Navegar a SolicitudScreen
|
||||
Get.offNamed('/solicitud');
|
||||
}
|
||||
|
||||
if (message.notification != null) {
|
||||
print('Message also contained a notification: ${message.notification}');
|
||||
}
|
||||
});
|
||||
|
||||
if (message.notification != null) {
|
||||
print('Message also contained a notification: ${message.notification}');
|
||||
}
|
||||
});
|
||||
|
||||
print('User granted permission: ${settings.authorizationStatus}');
|
||||
|
||||
@@ -76,25 +89,7 @@ void main() async {
|
||||
usePathUrlStrategy();
|
||||
runApp(const MyApp());
|
||||
}
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message, BuildContext context) async {
|
||||
final Map<String, dynamic> data = message.data;
|
||||
|
||||
if (data['click_action'] == 'FLUTTER_NOTIFICATION_CLICK') {
|
||||
final String screen = data['screen'];
|
||||
|
||||
if (screen == 'solicitud') {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => SolicitudScreen()),
|
||||
);
|
||||
} else if (screen == 'misservicios') {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => MyServicesScreen()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user