英文:
Why I got error of some methods that are not defined for dynamic links?
问题
final ShortDynamicLink shortLink = await parameters.buildShortDynamicLink();
url = shortLink.shortUrl;
url = await parameters.buildUrl();
英文:
I am trying to create dynamic links for deep linking purpose, but I've been recieving these errors for 2 methods and I'm not sure why they generate errors because these methods are the ones used when I searched about dynamic links. Are there methods replacing them, or how should I correct the code?
Error messages:
> The method 'buildShortLink' isn't defined for the type 'DynamicLinkParameters'.
> Try correcting the name to the name of an existing method, or defining a method named 'buildShortLink'.
> The method 'buildUrl' isn't defined for the type 'DynamicLinkParameters'.
> Try correcting the name to the name of an existing method, or defining a method named 'buildUrl'.
Code:
import 'dart:js';
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
import 'package:flutter/material.dart';
import 'package:myapp/providers/product_class.dart';
import 'package:url_launcher/url_launcher.dart';
class FirebaseDynamicLinkService{
Future<String> _createDynamicLink(bool short, Product product) async {
String _linkMessage='';
bool _isCreatingLink = false;
final DynamicLinkParameters parameters = DynamicLinkParameters(
uriPrefix: 'https://myapp.page.link',
link: Uri.parse(
'https://myapp/product?id=${product.documentID}',
),
// link: Uri.parse(DynamicLink),
androidParameters: const AndroidParameters(
packageName: 'com.example.myapp',
minimumVersion: 125,
),
);
Uri url;
if (short) {
final ShortDynamicLink shortLink =
await parameters.buildShortLink(); // here shows error
url = shortLink.shortUrl;
} else {
url = await parameters.buildUrl(); // here shows error
}
return _linkMessage;
}
}
I was expecting the code to not generate errors for these methods.
答案1
得分: 2
Replace the code as follows:
替换这部分代码:
if (short) {
final ShortDynamicLink shortLink =
await FirebaseDynamicLinks.instance.buildShortLink(parameters);
url = shortLink.shortUrl;
} else {
url = await FirebaseDynamicLinks.instance.buildLink(parameters);
}
For more information, check this link: https://firebase.google.com/docs/dynamic-links/flutter/create
英文:
you need to replace below code with suggested code
Replace this
if (short) {
final ShortDynamicLink shortLink =
await parameters.buildShortLink(); // here shows error
url = shortLink.shortUrl;
} else {
url = await parameters.buildUrl(); // here shows error
}
with this
if (short) {
final ShortDynamicLink shortLink =
await FirebaseDynamicLinks.instance.buildShortLink(parameters);
url = shortLink.shortUrl;
} else {
url = await FirebaseDynamicLinks.instance.buildLink(parameters);
}
For more information , check this https://firebase.google.com/docs/dynamic-links/flutter/create
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论