update
This commit is contained in:
+28
-35
@@ -25,8 +25,9 @@ import 'package:prosappco/src/screens/solicitudes.dart';
|
||||
import 'package:prosappco/src/services/local_notifications.dart';
|
||||
import 'firebase_options.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
//import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb; // Importa kIsWeb
|
||||
import 'dart:html' as html;
|
||||
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await Firebase.initializeApp();
|
||||
@@ -40,44 +41,29 @@ void main() async {
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
).then((value) => Get.put(AuthenticationRepository()));
|
||||
|
||||
FirebaseMessaging.onBackgroundMessage((_firebaseMessagingBackgroundHandler));
|
||||
// Evitar la solicitud de permiso en la versión web
|
||||
if (!kIsWeb) {
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
NotificationSettings settings = await messaging.requestPermission(
|
||||
alert: true,
|
||||
announcement: false,
|
||||
badge: true,
|
||||
carPlay: false,
|
||||
criticalAlert: false,
|
||||
provisional: false,
|
||||
sound: true,
|
||||
);
|
||||
|
||||
NotificationSettings settings = await messaging.requestPermission(
|
||||
alert: true,
|
||||
announcement: false,
|
||||
badge: true,
|
||||
carPlay: false,
|
||||
criticalAlert: false,
|
||||
provisional: false,
|
||||
sound: true,
|
||||
);
|
||||
print('User granted permission: ${settings.authorizationStatus}');
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
print('Got a message whilst in the foreground!');
|
||||
print('Message data: ${message.data}');
|
||||
FirebaseMessaging.onBackgroundMessage((_firebaseMessagingBackgroundHandler));
|
||||
|
||||
// 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');
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
// Tu código para manejar las notificaciones aquí
|
||||
});
|
||||
}
|
||||
|
||||
if (message.notification != null) {
|
||||
print('Message also contained a notification: ${message.notification}');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
print('User granted permission: ${settings.authorizationStatus}');
|
||||
|
||||
await initNotifications();
|
||||
|
||||
await initializeDateFormatting('es_MX', null);
|
||||
@@ -86,7 +72,14 @@ FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
usePathUrlStrategy();
|
||||
|
||||
html.window.onPopState.listen((event) {
|
||||
// Cuando cambia la URL, redirige a la ruta inicial
|
||||
html.window.history.replaceState(null, 'ProsApp', '/');
|
||||
// O puedes usar `pushState` si prefieres agregar una entrada al historial
|
||||
// html.window.history.pushState(null, 'ProsApp', '/');
|
||||
});
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@@ -101,8 +94,8 @@ class MyApp extends StatelessWidget {
|
||||
title: 'ProsApp',
|
||||
initialRoute: '/',
|
||||
routes: {
|
||||
'/splash': (context) => const SplashScreen(),
|
||||
'/': (context) => const LoginScreen(),
|
||||
'/splash': (context) => const SplashScreen(),
|
||||
'/login': (context) => const LoginEmailScreen(),
|
||||
'/profile': (context) => const ProfileScreen(),
|
||||
'/register': (context) => const RegisterScreen(),
|
||||
|
||||
Reference in New Issue
Block a user