0

I have predefined url from server and want to replace the string in flutter dart.

For example as follow. I have no idea what is the route it is but I know that if I found ${track_id}, replace with real value. Same for ${artist_id} and ${album_id} and return the real url.

https://thitsarparami.org/artist/${artist_id}/album/${album_id}/track/${track_id} https://thitsarparami.org/${artist_id}/${album_id}/${track_id}

May I know how to replace dynamically.

1

1 Answer 1

2

Check below example,

String refineUrl(String url) {

  if(url.contains("${album_id}")) {
    url = url.replaceAll("${album_id}", "<realAlbumId>");
  }
  // repeat the above check for all the dynamic values


  return url;
}

String url = "https://thitsarparami.org/artist/${artist_id}/album/${album_id}/track/${track_id}";

url = refineUrl(url);

Alternatively, you can send the albumId and other values through the function parameter.

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.