replay pending notification tap after login
This commit is contained in:
parent
80aa5822d3
commit
b793cb2a4b
|
|
@ -14,6 +14,7 @@ import 'package:didvan/services/auth/token_storage.dart';
|
|||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:didvan/services/notification/firebase_api.dart';
|
||||
import 'package:didvan/services/notification/notification_service.dart';
|
||||
import 'package:didvan/services/storage/storage.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
|
||||
|
|
@ -188,6 +189,13 @@ class UserProvider extends CoreProvier {
|
|||
// ignore: discarded_futures
|
||||
fetchWelcomeMessage();
|
||||
|
||||
// If the user reached us via a notification tap while logged out,
|
||||
// splash stashed the payload. Now that we're authenticated, replay
|
||||
// it so they land on the right detail screen instead of staying on
|
||||
// the home page.
|
||||
// ignore: discarded_futures
|
||||
NotificationService.consumePendingNotificationTap();
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
print("UserProvider: Exception processing user info: $e");
|
||||
|
|
|
|||
|
|
@ -72,6 +72,24 @@ class NotificationService {
|
|||
}
|
||||
}
|
||||
|
||||
/// Save a notification payload into cross-isolate storage so it can be
|
||||
/// replayed later (e.g. after the user logs in). Used by splash when the
|
||||
/// user tapped a notification while logged out — we don't want to drop
|
||||
/// the destination just because they need to sign in first.
|
||||
static Future<void> stashPendingNotificationPayload(
|
||||
NotificationMessage data) async {
|
||||
try {
|
||||
await HomeWidget.saveWidgetData(
|
||||
pendingNotificationPayloadKey,
|
||||
jsonEncode(data.toJson()),
|
||||
);
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('stashPendingNotificationPayload failed: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Read a pending notification payload (if any) from cross-isolate
|
||||
/// storage and hand it off to [HomeWidgetRepository.data] without
|
||||
/// navigating. Use this during splash where you want the existing splash
|
||||
|
|
|
|||
|
|
@ -378,6 +378,18 @@ class _SplashState extends State<Splash> with SingleTickerProviderStateMixin {
|
|||
return;
|
||||
}
|
||||
|
||||
// User tapped a notification but isn't logged in — stash the payload
|
||||
// back into cross-isolate storage so we can replay it after a
|
||||
// successful login (see UserProvider.getUserInfo).
|
||||
if (token == null && HomeWidgetRepository.data != null) {
|
||||
try {
|
||||
await NotificationService.stashPendingNotificationPayload(
|
||||
HomeWidgetRepository.data!,
|
||||
);
|
||||
} catch (_) {/* best effort */}
|
||||
HomeWidgetRepository.data = null;
|
||||
}
|
||||
|
||||
Navigator.of(context).pushReplacementNamed(
|
||||
destinationRoute,
|
||||
arguments: routeArguments,
|
||||
|
|
|
|||
Loading…
Reference in New Issue