我遇到了一些未定义为动态链接的方法的错误。

huangapple go评论69阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月18日 10:28:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定