navihate to notificatons when after click on push notification
This commit is contained in:
@@ -50,11 +50,14 @@ class LoginScreenRoute extends GoRouteData with _$LoginScreenRoute {
|
||||
// splash route - outside the shell
|
||||
@TypedGoRoute<SplashScreenRoute>(path: '/splash')
|
||||
class SplashScreenRoute extends GoRouteData with _$SplashScreenRoute {
|
||||
const SplashScreenRoute();
|
||||
final bool? navigateToNotification;
|
||||
const SplashScreenRoute({this.navigateToNotification});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return const SplashScreen();
|
||||
return SplashScreen(
|
||||
navigateToNotification: navigateToNotification ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,11 +51,24 @@ RouteBase get $splashScreenRoute => GoRouteData.$route(
|
||||
);
|
||||
|
||||
mixin _$SplashScreenRoute on GoRouteData {
|
||||
static SplashScreenRoute _fromState(GoRouterState state) =>
|
||||
const SplashScreenRoute();
|
||||
static SplashScreenRoute _fromState(GoRouterState state) => SplashScreenRoute(
|
||||
navigateToNotification: _$convertMapValue(
|
||||
'navigate-to-notification',
|
||||
state.uri.queryParameters,
|
||||
_$boolConverter,
|
||||
),
|
||||
);
|
||||
|
||||
SplashScreenRoute get _self => this as SplashScreenRoute;
|
||||
|
||||
@override
|
||||
String get location => GoRouteData.$location('/splash');
|
||||
String get location => GoRouteData.$location(
|
||||
'/splash',
|
||||
queryParams: {
|
||||
if (_self.navigateToNotification != null)
|
||||
'navigate-to-notification': _self.navigateToNotification!.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
void go(BuildContext context) => context.go(location);
|
||||
@@ -71,6 +84,26 @@ mixin _$SplashScreenRoute on GoRouteData {
|
||||
void replace(BuildContext context) => context.replace(location);
|
||||
}
|
||||
|
||||
T? _$convertMapValue<T>(
|
||||
String key,
|
||||
Map<String, String> map,
|
||||
T? Function(String) converter,
|
||||
) {
|
||||
final value = map[key];
|
||||
return value == null ? null : converter(value);
|
||||
}
|
||||
|
||||
bool _$boolConverter(String value) {
|
||||
switch (value) {
|
||||
case 'true':
|
||||
return true;
|
||||
case 'false':
|
||||
return false;
|
||||
default:
|
||||
throw UnsupportedError('Cannot convert "$value" into a bool.');
|
||||
}
|
||||
}
|
||||
|
||||
RouteBase get $appShellRouteData => StatefulShellRouteData.$route(
|
||||
parentNavigatorKey: AppShellRouteData.$parentNavigatorKey,
|
||||
factory: $AppShellRouteDataExtension._fromState,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// main.dart
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -53,6 +54,23 @@ class MyApp extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_handleInitialMessage();
|
||||
}
|
||||
|
||||
Future<void> _handleInitialMessage() async {
|
||||
final message = await FirebaseMessaging.instance.getInitialMessage();
|
||||
if (message != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
appRouter.go(
|
||||
const SplashScreenRoute(navigateToNotification: true).location,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
@@ -6,7 +6,8 @@ import 'package:tm_app/core/utils/size_config.dart';
|
||||
import 'package:tm_app/view_models/auth_view_model.dart';
|
||||
|
||||
class MobileSplashPage extends StatefulWidget {
|
||||
const MobileSplashPage({super.key});
|
||||
const MobileSplashPage({required this.navigateToNotification, super.key});
|
||||
final bool navigateToNotification;
|
||||
|
||||
@override
|
||||
State<MobileSplashPage> createState() => _MobileSplashPageState();
|
||||
@@ -27,7 +28,14 @@ class _MobileSplashPageState extends State<MobileSplashPage> {
|
||||
void _viewModelListener() {
|
||||
if (viewModel.isLoggedIn) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Router.neglect(context, () => const HomeRouteData().go(context));
|
||||
if (widget.navigateToNotification) {
|
||||
Router.neglect(
|
||||
context,
|
||||
() => const NotificationRouteData().go(context),
|
||||
);
|
||||
} else {
|
||||
Router.neglect(context, () => const HomeRouteData().go(context));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
|
||||
@@ -6,15 +6,16 @@ import 'package:tm_app/views/splash/pages/m_splash_page.dart';
|
||||
import 'package:tm_app/views/splash/pages/t_splash_page.dart';
|
||||
|
||||
class SplashScreen extends StatelessWidget {
|
||||
const SplashScreen({super.key});
|
||||
const SplashScreen({required this.navigateToNotification, super.key});
|
||||
final bool navigateToNotification;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SizeConfig.init(context);
|
||||
return const ResponsiveBuilder(
|
||||
mobile: MobileSplashPage(),
|
||||
tablet: TabletSplashPage(),
|
||||
desktop: DesktopSplashPage(),
|
||||
return ResponsiveBuilder(
|
||||
mobile: MobileSplashPage(navigateToNotification: navigateToNotification),
|
||||
tablet: const TabletSplashPage(),
|
||||
desktop: const DesktopSplashPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user