在 flutter 中启动 link

Launch link in flutter

我想启动自定义动态 links..

我有 getter 从数据库中加载字符串文本,这个字符串文本是用户输入的 IG 用户名 bio是IG用户名,exsample @instagram

 String getBio(String bio) {
if (widget.isMyProfile) {
  return bio;
} else if (bio == "") {
  return "";
} else {
  return bio;
}

}

我想要静态 link "**https://instagram.com/**;" 其中 link 的末尾将是动态 instagram 用户名 示例:'https://instagram.com/instagram';

_launchURLIG() async {
const url = 'https://instagram.com/';
if (await canLaunch(url)) {
  await launch(url);
} else {
  throw 'Could not launch $url';
}

}

===== 像这样的东西。 https://instagram.com' + getBio

_launchURLIG() async {
const url = 'https://instagram.com' + getBio ;
if (await canLaunch(url)) {
  await launch(url);
} else {
  throw 'Could not launch $url';
}

}

您应该将配置文件作为参数传递给您的函数

_launchURLIG(String userId) async {
String url = 'https://instagram.com/' + userId ;
if (await canLaunch(url)) {
  await launch(url);
} else {
  throw 'Could not launch $url';
}

也许您需要这个包来 运行 link: https://pub.dev/packages/url_launcher