I have stateless widget contain future function to get a value (not a list) from database:
Future<int> getUserStatus() async {
var url =
"http:/xxxxxx/api/controller/users/status_user.php?username=$username";
var response = await http.get(url);
var data = jsonDecode(response.body);
var savedDayID = int.parse(data['d_id'].toString());
return savedDayID;
}
How can I put the value returned in a variable?
In general:
final myVariable = await getUserStatus();
Make sure to handle the exception that int.parse() could throw.
For building UI components, have a look at the FutureBuilder.
I'd reconsider the design of trying to do url fetching inside the build method. The reason being that the build method should be possible to run many times at the will of the framework.