31 lines
769 B
Dart
31 lines
769 B
Dart
import 'package:dio/dio.dart';
|
|
|
|
class ApiService {
|
|
final Dio dio;
|
|
|
|
ApiService({required String baseUrl})
|
|
: dio = Dio(BaseOptions(
|
|
baseUrl: baseUrl,
|
|
connectTimeout: const Duration(seconds: 5),
|
|
receiveTimeout: const Duration(seconds: 3),
|
|
));
|
|
|
|
Future<List<dynamic>> fetchHeroes() async {
|
|
try {
|
|
final response = await dio.get('/v2/heroes');
|
|
return response.data as List<dynamic>;
|
|
} catch (e) {
|
|
throw Exception('Failed to load heroes: $e');
|
|
}
|
|
}
|
|
|
|
Future<Map<String, dynamic>> fetchHeroDetails(int id) async {
|
|
try {
|
|
final response = await dio.get('/v2/heroes/$id');
|
|
return response.data as Map<String, dynamic>;
|
|
} catch (e) {
|
|
throw Exception('Failed to load hero details: $e');
|
|
}
|
|
}
|
|
}
|