0

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.

1 Answers1

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