-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
firebase_dynamic_links.dart
89 lines (75 loc) 路 3.37 KB
/
firebase_dynamic_links.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of firebase_dynamic_links;
/// Firebase Dynamic Links API.
///
/// You can get an instance by calling [FirebaseDynamicLinks.instance].
class FirebaseDynamicLinks extends FirebasePluginPlatform {
FirebaseDynamicLinks._({required this.app})
: super(app.name, 'plugins.flutter.io/firebase_dynamic_links');
static final Map<String, FirebaseDynamicLinks> _cachedInstances = {};
/// Returns an instance using the default [FirebaseApp].
static FirebaseDynamicLinks get instance {
return FirebaseDynamicLinks.instanceFor(
app: Firebase.app(),
);
}
/// Returns an instance using a specified [FirebaseApp].
/// Note; multi-app support is only supported on android.
static FirebaseDynamicLinks instanceFor({required FirebaseApp app}) {
if (defaultTargetPlatform == TargetPlatform.android ||
app.name == defaultFirebaseAppName) {
return _cachedInstances.putIfAbsent(app.name, () {
FirebaseDynamicLinks newInstance = FirebaseDynamicLinks._(app: app);
FirebasePluginPlatform.verify(newInstance);
return newInstance;
});
}
throw UnsupportedError(
'FirebaseDynamicLinks.instanceFor() only supports non-default FirebaseApp instances on Android.',
);
}
// Cached and lazily loaded instance of [FirebaseDynamicLinksPlatform] to avoid
// creating a [MethodChannelFirebaseDynamicLinks] when not needed or creating an
// instance with the default app before a user specifies an app.
FirebaseDynamicLinksPlatform? _delegatePackingProperty;
FirebaseDynamicLinksPlatform get _delegate {
return _delegatePackingProperty ??=
FirebaseDynamicLinksPlatform.instanceFor(app: app);
}
/// The [FirebaseApp] for this current [FirebaseDynamicLinks] instance.
FirebaseApp app;
/// Attempts to retrieve the dynamic link which launched the app.
///
/// This method always returns a Future. That Future completes to null if
/// there is no pending dynamic link or any call to this method after the
/// the first attempt.
Future<PendingDynamicLinkData?> getInitialLink() async {
return _delegate.getInitialLink();
}
/// Determine if the app has a pending dynamic link and provide access to
/// the dynamic link parameters. A pending dynamic link may have been
/// previously captured when a user clicked on a dynamic link, or
/// may be present in the dynamicLinkUri parameter. If both are present,
/// the previously captured dynamic link will take precedence. The captured
/// data will be removed after first access.
Future<PendingDynamicLinkData?> getDynamicLink(Uri url) async {
return _delegate.getDynamicLink(url);
}
/// Listen to a stream for the latest dynamic link events.
Stream<PendingDynamicLinkData> get onLink {
return _delegate.onLink;
}
/// Creates a Dynamic Link from the parameters.
Future<Uri> buildLink(DynamicLinkParameters parameters) async {
return _delegate.buildLink(parameters);
}
/// Creates a shortened Dynamic Link from the parameters.
Future<ShortDynamicLink> buildShortLink(
DynamicLinkParameters parameters, {
ShortDynamicLinkType shortLinkType = ShortDynamicLinkType.short,
}) async {
return _delegate.buildShortLink(parameters, shortLinkType: shortLinkType);
}
}