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 'package:prosappco/src/services/local_notifications.dart';
|
||||||
import 'firebase_options.dart';
|
import 'firebase_options.dart';
|
||||||
import 'package:firebase_messaging/firebase_messaging.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 'package:flutter/foundation.dart' show kIsWeb; // Importa kIsWeb
|
||||||
|
import 'dart:html' as html;
|
||||||
|
|
||||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||||
await Firebase.initializeApp();
|
await Firebase.initializeApp();
|
||||||
@@ -40,44 +41,29 @@ void main() async {
|
|||||||
options: DefaultFirebaseOptions.currentPlatform,
|
options: DefaultFirebaseOptions.currentPlatform,
|
||||||
).then((value) => Get.put(AuthenticationRepository()));
|
).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(
|
print('User granted permission: ${settings.authorizationStatus}');
|
||||||
alert: true,
|
|
||||||
announcement: false,
|
|
||||||
badge: true,
|
|
||||||
carPlay: false,
|
|
||||||
criticalAlert: false,
|
|
||||||
provisional: false,
|
|
||||||
sound: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
FirebaseMessaging.onBackgroundMessage((_firebaseMessagingBackgroundHandler));
|
||||||
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
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||||
String? notificationScreen = message.data['screen'];
|
// Tu código para manejar las notificaciones aquí
|
||||||
|
});
|
||||||
// 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}');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
print('User granted permission: ${settings.authorizationStatus}');
|
|
||||||
|
|
||||||
await initNotifications();
|
await initNotifications();
|
||||||
|
|
||||||
await initializeDateFormatting('es_MX', null);
|
await initializeDateFormatting('es_MX', null);
|
||||||
@@ -86,7 +72,14 @@ FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
|||||||
DeviceOrientation.portraitUp,
|
DeviceOrientation.portraitUp,
|
||||||
DeviceOrientation.portraitDown,
|
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());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +94,8 @@ class MyApp extends StatelessWidget {
|
|||||||
title: 'ProsApp',
|
title: 'ProsApp',
|
||||||
initialRoute: '/',
|
initialRoute: '/',
|
||||||
routes: {
|
routes: {
|
||||||
'/splash': (context) => const SplashScreen(),
|
|
||||||
'/': (context) => const LoginScreen(),
|
'/': (context) => const LoginScreen(),
|
||||||
|
'/splash': (context) => const SplashScreen(),
|
||||||
'/login': (context) => const LoginEmailScreen(),
|
'/login': (context) => const LoginEmailScreen(),
|
||||||
'/profile': (context) => const ProfileScreen(),
|
'/profile': (context) => const ProfileScreen(),
|
||||||
'/register': (context) => const RegisterScreen(),
|
'/register': (context) => const RegisterScreen(),
|
||||||
|
|||||||
Reference in New Issue
Block a user