0

I'm trying to read a dynamic link that I created on firebase inside my flutter application, I did all the configuration but I'm always getting null as a value.

Here is my firebase config:

Shortlink: https://******.page.link/test

Dynamic link: https://*******.tn/restaurant?id=64fdf73f3ac564fe091a22e6

my android manifest file code:

 <meta-data 
                android:name="flutter_deeplinking_enabled" 
                android:value="true"/>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" />
                <data android:host="******.page.link" />
            </intent-filter>

And here is how i'm trying to read the dynamic link:

Future<void> initDynamicLinks() async {
  print("Initial DynamicLinks");
  FirebaseDynamicLinks dynamicLinks = FirebaseDynamicLinks.instance;

  dynamicLinks.onLink.listen((dynamicLinkData) {
    final Uri uri = dynamicLinkData.link;
    final queryParams = uri.queryParameters;
    if (queryParams.isNotEmpty) {
      print("Incoming Link :" + uri.toString());
    } else {
      print("No Current Links");
    }
  });

  PendingDynamicLinkData? data = await dynamicLinks
      .getDynamicLink(Uri.parse("https://******.page.link/test"));
  final Uri uri = data!.link;
  if (uri != null) {
    print("Found The Searched Link: " + uri.toString());
  } else {
    print("Search Link Not Found");
  }
}

and this is my main function:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  initDynamicLinks();
}

It doesn't return me anything and actually it does not listen to any links, note that i'm running it on an android physical device on debug mode. Thanks for your help!

2
  • how are you testing the link in debug app? have you followed this tutorial ? firebase.google.com/docs/dynamic-links/flutter/receive Commented Apr 25, 2024 at 9:15
  • Actually moving the block of code to a separate page instead of doing it all inside main function gave a result, and while on debug mode! Commented Apr 25, 2024 at 9:17

1 Answer 1

0

Moving the whole block to a separate widget and calling the function inside initState solved the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.