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
|
// splash route - outside the shell
|
||||||
@TypedGoRoute<SplashScreenRoute>(path: '/splash')
|
@TypedGoRoute<SplashScreenRoute>(path: '/splash')
|
||||||
class SplashScreenRoute extends GoRouteData with _$SplashScreenRoute {
|
class SplashScreenRoute extends GoRouteData with _$SplashScreenRoute {
|
||||||
const SplashScreenRoute();
|
final bool? navigateToNotification;
|
||||||
|
const SplashScreenRoute({this.navigateToNotification});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, GoRouterState state) {
|
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 {
|
mixin _$SplashScreenRoute on GoRouteData {
|
||||||
static SplashScreenRoute _fromState(GoRouterState state) =>
|
static SplashScreenRoute _fromState(GoRouterState state) => SplashScreenRoute(
|
||||||
const SplashScreenRoute();
|
navigateToNotification: _$convertMapValue(
|
||||||
|
'navigate-to-notification',
|
||||||
|
state.uri.queryParameters,
|
||||||
|
_$boolConverter,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
SplashScreenRoute get _self => this as SplashScreenRoute;
|
||||||
|
|
||||||
@override
|
@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
|
@override
|
||||||
void go(BuildContext context) => context.go(location);
|
void go(BuildContext context) => context.go(location);
|
||||||
@@ -71,6 +84,26 @@ mixin _$SplashScreenRoute on GoRouteData {
|
|||||||
void replace(BuildContext context) => context.replace(location);
|
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(
|
RouteBase get $appShellRouteData => StatefulShellRouteData.$route(
|
||||||
parentNavigatorKey: AppShellRouteData.$parentNavigatorKey,
|
parentNavigatorKey: AppShellRouteData.$parentNavigatorKey,
|
||||||
factory: $AppShellRouteDataExtension._fromState,
|
factory: $AppShellRouteDataExtension._fromState,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// main.dart
|
// main.dart
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -53,6 +54,23 @@ class MyApp extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyAppState extends State<MyApp> {
|
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
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.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';
|
import 'package:tm_app/view_models/auth_view_model.dart';
|
||||||
|
|
||||||
class MobileSplashPage extends StatefulWidget {
|
class MobileSplashPage extends StatefulWidget {
|
||||||
const MobileSplashPage({super.key});
|
const MobileSplashPage({required this.navigateToNotification, super.key});
|
||||||
|
final bool navigateToNotification;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MobileSplashPage> createState() => _MobileSplashPageState();
|
State<MobileSplashPage> createState() => _MobileSplashPageState();
|
||||||
@@ -27,7 +28,14 @@ class _MobileSplashPageState extends State<MobileSplashPage> {
|
|||||||
void _viewModelListener() {
|
void _viewModelListener() {
|
||||||
if (viewModel.isLoggedIn) {
|
if (viewModel.isLoggedIn) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (widget.navigateToNotification) {
|
||||||
|
Router.neglect(
|
||||||
|
context,
|
||||||
|
() => const NotificationRouteData().go(context),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
Router.neglect(context, () => const HomeRouteData().go(context));
|
Router.neglect(context, () => const HomeRouteData().go(context));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
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';
|
import 'package:tm_app/views/splash/pages/t_splash_page.dart';
|
||||||
|
|
||||||
class SplashScreen extends StatelessWidget {
|
class SplashScreen extends StatelessWidget {
|
||||||
const SplashScreen({super.key});
|
const SplashScreen({required this.navigateToNotification, super.key});
|
||||||
|
final bool navigateToNotification;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
SizeConfig.init(context);
|
SizeConfig.init(context);
|
||||||
return const ResponsiveBuilder(
|
return ResponsiveBuilder(
|
||||||
mobile: MobileSplashPage(),
|
mobile: MobileSplashPage(navigateToNotification: navigateToNotification),
|
||||||
tablet: TabletSplashPage(),
|
tablet: const TabletSplashPage(),
|
||||||
desktop: DesktopSplashPage(),
|
desktop: const DesktopSplashPage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user