mirror of
https://github.com/block/buzz.git
synced 2026-11-01 15:01:12 +00:00
Signed-off-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub1jmc9dt2lyvzu3h0kxlwxt5zg4fxp9476awyxw6gwxn72g6cw7exqs64whm <96f056ad5f2305c8ddf637dc65d048aa4c12d7daeb8867690e34fca46b0ef64c@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1jmc9dt2lyvzu3h0kxlwxt5zg4fxp9476awyxw6gwxn72g6cw7exqs64whm <96f056ad5f2305c8ddf637dc65d048aa4c12d7daeb8867690e34fca46b0ef64c@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:app_links/app_links.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'deep_link.dart';
|
|
|
|
/// Holds the most recent supported deep link that has not been
|
|
/// dispatched yet.
|
|
///
|
|
/// Listens to [AppLinks.uriLinkStream], which delivers both the cold-start
|
|
/// link (the URL that launched the app) and links received while running.
|
|
/// Navigation cannot always happen the moment a link arrives — the user may
|
|
/// not be authenticated yet, or channels may still be loading — so the parsed
|
|
/// link is parked here and consumed by the dispatcher once the app is ready.
|
|
class PendingDeepLinkNotifier extends Notifier<BuzzDeepLink?> {
|
|
@visibleForTesting
|
|
static Stream<Uri>? debugUriStreamOverride;
|
|
|
|
StreamSubscription<Uri>? _subscription;
|
|
|
|
@override
|
|
BuzzDeepLink? build() {
|
|
final stream = debugUriStreamOverride ?? AppLinks().uriLinkStream;
|
|
_subscription = stream.listen(handleUri);
|
|
ref.onDispose(() {
|
|
_subscription?.cancel();
|
|
_subscription = null;
|
|
});
|
|
return null;
|
|
}
|
|
|
|
/// Parse and park an incoming URI. Unsupported links are ignored loudly.
|
|
@visibleForTesting
|
|
void handleUri(Uri uri) {
|
|
final link = parseBuzzDeepLink(uri);
|
|
if (link == null) {
|
|
debugPrint('deep-link: ignoring unsupported link: $uri');
|
|
return;
|
|
}
|
|
state = link;
|
|
}
|
|
|
|
/// Clear the pending link after it has been dispatched (or dropped).
|
|
void consume() => state = null;
|
|
}
|
|
|
|
final pendingDeepLinkProvider =
|
|
NotifierProvider<PendingDeepLinkNotifier, BuzzDeepLink?>(
|
|
PendingDeepLinkNotifier.new,
|
|
);
|