web show notification when push notification is recieved
This commit is contained in:
+48
-27
@@ -13,6 +13,8 @@ import 'package:tm_app/core/config/web_url_strategy.dart';
|
||||
import 'package:tm_app/core/services/cache_init.dart';
|
||||
import 'package:tm_app/core/services/firebase_service.dart';
|
||||
import 'package:tm_app/core/theme/theme_provider.dart';
|
||||
import 'package:tm_app/core/utils/app_toast.dart';
|
||||
import 'package:toastification/toastification.dart';
|
||||
|
||||
import 'core/routes/app_routes.dart';
|
||||
import 'core/theme/colors.dart';
|
||||
@@ -61,6 +63,21 @@ class _MyAppState extends State<MyApp> {
|
||||
_handleMessage(initialMessage);
|
||||
}
|
||||
|
||||
if (kIsWeb) {
|
||||
FirebaseMessaging.onMessage.listen((event) {
|
||||
final overlayCtx = rootNavigatorKey.currentContext;
|
||||
if (overlayCtx != null) {
|
||||
if (overlayCtx.mounted) {
|
||||
AppToast.notification(
|
||||
overlayCtx,
|
||||
event.notification?.title ?? 'New Notification',
|
||||
event.notification?.body ?? 'New Notification',
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FirebaseMessaging.onMessageOpenedApp.listen(_handleMessage);
|
||||
}
|
||||
|
||||
@@ -73,7 +90,9 @@ class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setupInteractedMessage();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
setupInteractedMessage();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -88,38 +107,40 @@ class _MyAppState extends State<MyApp> {
|
||||
// Listen to theme changes
|
||||
final themeProvider = context.watch<ThemeProvider>();
|
||||
|
||||
return MaterialApp.router(
|
||||
title: 'OppLens',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scrollBehavior: const MaterialScrollBehavior().copyWith(
|
||||
dragDevices: {
|
||||
PointerDeviceKind.mouse,
|
||||
PointerDeviceKind.touch,
|
||||
PointerDeviceKind.stylus,
|
||||
PointerDeviceKind.unknown,
|
||||
},
|
||||
),
|
||||
theme: ThemeData(
|
||||
pageTransitionsTheme: PageTransitionsTheme(
|
||||
builders: {
|
||||
for (final platform in TargetPlatform.values)
|
||||
platform:
|
||||
kIsWeb
|
||||
? const FadeUpwardsPageTransitionsBuilder()
|
||||
: const CupertinoPageTransitionsBuilder(),
|
||||
return ToastificationWrapper(
|
||||
child: MaterialApp.router(
|
||||
title: 'OppLens',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scrollBehavior: const MaterialScrollBehavior().copyWith(
|
||||
dragDevices: {
|
||||
PointerDeviceKind.mouse,
|
||||
PointerDeviceKind.touch,
|
||||
PointerDeviceKind.stylus,
|
||||
PointerDeviceKind.unknown,
|
||||
},
|
||||
),
|
||||
brightness:
|
||||
themeProvider.isDarkMode ? Brightness.dark : Brightness.light,
|
||||
primaryColor: AppColors.primaryColor,
|
||||
scaffoldBackgroundColor: AppColors.backgroundColor,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: AppColors.primaryColor,
|
||||
theme: ThemeData(
|
||||
pageTransitionsTheme: PageTransitionsTheme(
|
||||
builders: {
|
||||
for (final platform in TargetPlatform.values)
|
||||
platform:
|
||||
kIsWeb
|
||||
? const FadeUpwardsPageTransitionsBuilder()
|
||||
: const CupertinoPageTransitionsBuilder(),
|
||||
},
|
||||
),
|
||||
brightness:
|
||||
themeProvider.isDarkMode ? Brightness.dark : Brightness.light,
|
||||
primaryColor: AppColors.primaryColor,
|
||||
scaffoldBackgroundColor: AppColors.backgroundColor,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: AppColors.primaryColor,
|
||||
brightness:
|
||||
themeProvider.isDarkMode ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
),
|
||||
routerConfig: appRouter,
|
||||
),
|
||||
routerConfig: appRouter,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user