Skip to content

Commit 80e5e08

Browse files
authored
Merge pull request #147 from MostroP2P/fix/null-check-operator-deep-link
Fixed Null check operator used on a null value err
2 parents 5402a0c + 6129d50 commit 80e5e08

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lib/core/app_routes.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ GoRouter createRouter(WidgetRef ref) {
3131
navigatorKey: GlobalKey<NavigatorState>(),
3232
initialLocation: '/',
3333
redirect: (context, state) {
34+
// Redirect custom schemes to home to prevent assertion failures
35+
if (state.uri.scheme == 'mostro' ||
36+
(!state.uri.scheme.startsWith('http') && state.uri.scheme.isNotEmpty)) {
37+
return '/';
38+
}
3439
final firstRunState = ref.read(firstRunProvider);
3540

3641
return firstRunState.when(

lib/core/deep_link_handler.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,23 @@ class DeepLinkHandler {
7272
try {
7373
// Show loading indicator
7474
context = router.routerDelegate.navigatorKey.currentContext;
75-
if (context != null) {
75+
if (context != null && context.mounted) {
7676
_showLoadingDialog(context);
7777
}
7878

7979
// Get the services
8080
final nostrService = _ref.read(nostrServiceProvider);
8181
final deepLinkService = _ref.read(deepLinkServiceProvider);
8282

83+
// Ensure we have a valid context for processing
84+
final processingContext = context ?? router.routerDelegate.navigatorKey.currentContext;
85+
if (processingContext == null || !processingContext.mounted) {
86+
_logger.e('No valid context available for deep link processing');
87+
return;
88+
}
89+
8390
// Process the mostro link
84-
final result = await deepLinkService.processMostroLink(url, nostrService, context!);
91+
final result = await deepLinkService.processMostroLink(url, nostrService, processingContext);
8592

8693
// Get fresh context after async operation
8794
final currentContext = router.routerDelegate.navigatorKey.currentContext;

lib/core/deep_link_interceptor.dart

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class DeepLinkInterceptor extends WidgetsBindingObserver {
2121
@override
2222
Future<bool> didPushRouteInformation(RouteInformation routeInformation) async {
2323
final uri = routeInformation.uri;
24-
_logger.i('Route information received: $uri');
24+
_logger.i('DeepLinkInterceptor: Route information received: $uri');
2525

2626
// Check if this is a custom scheme URL
2727
if (_isCustomScheme(uri)) {
28-
_logger.i('Custom scheme detected: ${uri.scheme}, intercepting');
28+
_logger.i('DeepLinkInterceptor: Custom scheme detected: ${uri.scheme}, intercepting and preventing GoRouter processing');
2929

3030
// Emit the custom URL for processing
3131
_customUrlController.add(uri.toString());
@@ -35,12 +35,32 @@ class DeepLinkInterceptor extends WidgetsBindingObserver {
3535
return true;
3636
}
3737

38+
_logger.i('DeepLinkInterceptor: Allowing normal URL to pass through: $uri');
3839
// Let normal URLs pass through to GoRouter
3940
return super.didPushRouteInformation(routeInformation);
4041
}
4142

4243
// Note: didPushRoute is deprecated, but we keep it for compatibility
4344
// The main handling is done in didPushRouteInformation above
45+
@override
46+
// ignore: deprecated_member_use
47+
Future<bool> didPushRoute(String route) async {
48+
_logger.i('DeepLinkInterceptor: didPushRoute called with: $route');
49+
50+
try {
51+
final uri = Uri.parse(route);
52+
if (_isCustomScheme(uri)) {
53+
_logger.i('DeepLinkInterceptor: Custom scheme detected in didPushRoute: ${uri.scheme}, intercepting');
54+
_customUrlController.add(route);
55+
return true;
56+
}
57+
} catch (e) {
58+
_logger.w('DeepLinkInterceptor: Error parsing route in didPushRoute: $e');
59+
}
60+
61+
// ignore: deprecated_member_use
62+
return super.didPushRoute(route);
63+
}
4464

4565
/// Check if the URI uses a custom scheme
4666
bool _isCustomScheme(Uri uri) {

0 commit comments

Comments
 (0)