Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions lib/core/config/router/route_guard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,33 @@ class RouteGuard {
String? Function() getPendingRoute,
void Function(String?) setPendingRoute,
) async {
final hasOnboarded = await onboardingRepo.isOnboardingCompleted().then(
(result) =>
result.fold((failure) => false, (hasCompleted) => hasCompleted),
);

// Force onboarding if not completed
if (!hasOnboarded &&
path != AppRoutes.onboarding &&
path != AppRoutes.login) {
return AppRoutes.onboarding;
}

// Skip onboarding if already done
if (hasOnboarded && path == AppRoutes.onboarding) {
// Onboarding is temporarily disabled for everyone. Never force it, and
// send any direct navigation to /onboarding back to home. This also fixes
// the offline case, where the original check below defaulted to "not
// onboarded" and wrongly forced onboarding.
if (path == AppRoutes.onboarding) {
return AppRoutes.home;
}

// Original force-onboarding logic, preserved (commented out) so it can be
// re-enabled later by deleting the redirect above and uncommenting this.
// final hasOnboarded = await onboardingRepo.isOnboardingCompleted().then(
// (result) =>
// result.fold((failure) => false, (hasCompleted) => hasCompleted),
// );
//
// // Force onboarding if not completed
// if (!hasOnboarded &&
// path != AppRoutes.onboarding &&
// path != AppRoutes.login) {
// return AppRoutes.onboarding;
// }
//
// // Skip onboarding if already done
// if (hasOnboarded && path == AppRoutes.onboarding) {
// return AppRoutes.home;
// }

// Redirect from login or splash to pending route or home
if (path == AppRoutes.login || path == AppRoutes.splash) {
final pending = getPendingRoute();
Expand Down
12 changes: 9 additions & 3 deletions lib/core/deep_linking/app_links_deep_link_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

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

_pendingUri = null;
_dispatch(pending);
_dispatch(pending, baseLocation: AppRoutes.home);
return true;
}

Expand All @@ -81,10 +82,15 @@ class AppLinksDeepLinkService {
_dispatch(uri);
}

void _dispatch(Uri uri) {
void _dispatch(Uri uri, {String? baseLocation}) {
final router = _router;
if (router == null) return;

DeepLinkRouter.route(uri, router, source: 'app_links');
DeepLinkRouter.route(
uri,
router,
source: 'app_links',
baseLocation: baseLocation,
);
}
}
15 changes: 13 additions & 2 deletions lib/core/deep_linking/deep_link_router.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_pecha/core/config/router/app_routes.dart';
import 'package:flutter_pecha/core/utils/app_logger.dart';
import 'package:flutter_pecha/features/reader/data/models/navigation_context.dart';
Expand All @@ -8,7 +9,12 @@ class DeepLinkRouter {

static final _logger = AppLogger('DeepLinkRouter');

static bool route(Uri uri, GoRouter router, {required String source}) {
static bool route(
Uri uri,
GoRouter router, {
required String source,
String? baseLocation,
}) {
try {
final destination = _resolveRoute(uri);
if (destination == null) {
Expand All @@ -17,7 +23,12 @@ class DeepLinkRouter {
}

_logger.info('Deep link from $source -> ${destination.location} ($uri)');
if (destination.opensOnTop) {
if (destination.opensOnTop && baseLocation != null) {
router.go(baseLocation);
WidgetsBinding.instance.addPostFrameCallback((_) {
router.push(destination.location, extra: destination.extra);
});
} else if (destination.opensOnTop) {
router.push(destination.location, extra: destination.extra);
} else {
router.go(destination.location, extra: destination.extra);
Expand Down
Loading
Loading