You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
|
|
import 'package:no_context_navigation/no_context_navigation.dart';
|
|
|
|
class DynamicLinkService {
|
|
Future handleDynamicLinks() async {
|
|
// 1. Get the initial dynamic link if the app is opened with a dynamic link
|
|
final PendingDynamicLinkData data =
|
|
await FirebaseDynamicLinks.instance.getInitialLink();
|
|
|
|
// 2. handle link that has been retrieved
|
|
_handleDeepLink(data);
|
|
|
|
// 3. Register a link callback to fire if the app is opened up from the background
|
|
// using a dynamic link.
|
|
FirebaseDynamicLinks.instance.onLink(
|
|
onSuccess: (PendingDynamicLinkData dynamicLink) async {
|
|
// 3a. handle link that has been retrieved
|
|
_handleDeepLink(dynamicLink);
|
|
}, onError: (OnLinkErrorException e) async {
|
|
print('Link Failed: ${e.message}');
|
|
});
|
|
}
|
|
|
|
void _handleDeepLink(PendingDynamicLinkData data) {
|
|
final Uri deepLink = data?.link;
|
|
if (deepLink != null) {
|
|
try {
|
|
if (deepLink.pathSegments.contains('resetpassword')) {
|
|
var guid = deepLink.queryParameters['resetguid'];
|
|
if (guid != null) {
|
|
navService.pushNamed('/resetpassword', args: guid);
|
|
}
|
|
} else if (deepLink.pathSegments.contains('referral')) {
|
|
var guid = deepLink.queryParameters['referrer'];
|
|
if (guid != null) {
|
|
navService.pushNamed('/login', args: guid);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|