how can i get a number from a get method from an api and display it in a text widget in flutter (my api return just an integer) not in json format

Viewed 44
Future<String> getNumberIntervention() async {
  final response = await http.get(
      Uri.parse('my url'));
  if (response.statusCode == 200) {
    
    String jsonResponse = json.decode(response.body);
    return jsonResponse.toString();
  } else {
    
    throw Exception('Failed to load Clients');
  }
}

when i call my api it returns number 2 without brakets so it's a no json format
how can i read this data and display it in a text widget in the dashboard

2 Answers

You can use FutureBuilder widget. Try it

FutureBuilder(
  future: getNumberIntervention(),
  builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
    if (snapshot.hasData) {
      return Text(snapshot.data!);
    }
    return const Text('Carregando');
  },
)
Related