Skip to content

Commit 5c362c8

Browse files
authored
Merge pull request #465 from OpenPecha/feat/deeplinkshare
feat: enhance deep link routing by adding base location support
2 parents b2d6deb + 8e44ca0 commit 5c362c8

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

lib/core/deep_linking/app_links_deep_link_service.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:app_links/app_links.dart';
4+
import 'package:flutter_pecha/core/config/router/app_routes.dart';
45
import 'package:flutter_pecha/core/deep_linking/deep_link_router.dart';
56
import 'package:flutter_pecha/core/utils/app_logger.dart';
67
import 'package:go_router/go_router.dart';
@@ -56,7 +57,7 @@ class AppLinksDeepLinkService {
5657
if (pending == null) return false;
5758

5859
_pendingUri = null;
59-
_dispatch(pending);
60+
_dispatch(pending, baseLocation: AppRoutes.home);
6061
return true;
6162
}
6263

@@ -81,10 +82,15 @@ class AppLinksDeepLinkService {
8182
_dispatch(uri);
8283
}
8384

84-
void _dispatch(Uri uri) {
85+
void _dispatch(Uri uri, {String? baseLocation}) {
8586
final router = _router;
8687
if (router == null) return;
8788

88-
DeepLinkRouter.route(uri, router, source: 'app_links');
89+
DeepLinkRouter.route(
90+
uri,
91+
router,
92+
source: 'app_links',
93+
baseLocation: baseLocation,
94+
);
8995
}
9096
}

lib/core/deep_linking/deep_link_router.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/widgets.dart';
12
import 'package:flutter_pecha/core/config/router/app_routes.dart';
23
import 'package:flutter_pecha/core/utils/app_logger.dart';
34
import 'package:flutter_pecha/features/reader/data/models/navigation_context.dart';
@@ -8,7 +9,12 @@ class DeepLinkRouter {
89

910
static final _logger = AppLogger('DeepLinkRouter');
1011

11-
static bool route(Uri uri, GoRouter router, {required String source}) {
12+
static bool route(
13+
Uri uri,
14+
GoRouter router, {
15+
required String source,
16+
String? baseLocation,
17+
}) {
1218
try {
1319
final destination = _resolveRoute(uri);
1420
if (destination == null) {
@@ -17,7 +23,12 @@ class DeepLinkRouter {
1723
}
1824

1925
_logger.info('Deep link from $source -> ${destination.location} ($uri)');
20-
if (destination.opensOnTop) {
26+
if (destination.opensOnTop && baseLocation != null) {
27+
router.go(baseLocation);
28+
WidgetsBinding.instance.addPostFrameCallback((_) {
29+
router.push(destination.location, extra: destination.extra);
30+
});
31+
} else if (destination.opensOnTop) {
2132
router.push(destination.location, extra: destination.extra);
2233
} else {
2334
router.go(destination.location, extra: destination.extra);

0 commit comments

Comments
 (0)