Ad

Launch Link In Flutter

- 1 answer

i would like to launch custom dynamic links..

i have getter which load string text from database, this string text is user input with them IG username bio is IG username, exsample @instagram

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

}

i want to have static link "**https://instagram.com/**;" where end of link will be dynamic instagram user name example: 'https://instagram.com/instagram';

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

}

===== something like this. 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';
}

}

Ad

Answer

You should past profile as a parameter to your function

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