I am using one String type variable e.g. String API_URL= "http://www.example.com";
Now I want set API_URL value to set by returned from internet. So I am trying Future getURL() async{...} function but I am not sure how to store return value in variable and how my app will wait until its value getting stored in this variable. I have no code to show. So please help with a snippet.
Asked
Active
Viewed 256 times
0
1 Answers
0
You can do it like this,
FutureBuilder(
future: http.get(yourUrl),
builder: (BuildContext context, snapshot) {
if(snapshot.hasData){
//Your code..mayb return a listView builder.
}
}
)
Update 1
You can initialise the String in an async
function and then call the function in initState ()

Madhavam Shahi
- 1,166
- 6
- 17
-
But I want to store it in variable like String API_URL = Get_API_URL(); – curious-developer Aug 30 '20 at 13:00
-
OK, Thanks. I will try in that way. – curious-developer Aug 31 '20 at 05:49