import 'dart:convert'; import 'package:http/http.dart' as http; class ApiService { final String baseUrl; ApiService({required this.baseUrl}); Future> fetchHeroes() async { final response = await http.get(Uri.parse('$baseUrl/v2/heroes')); if (response.statusCode == 200) { return json.decode(response.body) as List; } else { throw Exception('Failed to load heroes'); } } Future> fetchHeroDetails(int id) async { final response = await http.get(Uri.parse('$baseUrl/v2/heroes/$id')); if (response.statusCode == 200) { return json.decode(response.body) as Map; } else { throw Exception('Failed to load hero details'); } } Future> searchHeroByName(String name) async { final response = await http.get(Uri.parse('$baseUrl/v2/heroes/by-name/$name')); if (response.statusCode == 200) { return json.decode(response.body) as Map; } else { throw Exception('Failed to search hero'); } } }