I created an api that counts total category in my database table using laravel, and am trying to consume it in flutter and display the total count value. Please how can i achieve that
My Code:
//Laravel Query that count
public function count_categories(){
$count_category = DB::table('category_menu')
->count();
return response()->json($count_category);
}
//Flutter Code
//API URL
static const COUNT_CATEGORY = "/count_category";
Future<List<Category>> countCategory() async {
String countCategory = COUNT_CATEGORY;
Map<String, String> headers = {'Accept': 'application/json'};
var response = await http.get(countCategory, headers: headers);
if (response.statusCode == 200) {
var body = jsonDecode(response.body);
print(response.body);
}
}
//The response.body is printing the count value correctly, how can i display the response body result in a class widget?