import 'package:dio/dio.dart'; import 'package:flutter_app/data/mappers/%D1%81ocktail_mapper.dart'; import 'package:flutter_app/domain/models/card.dart'; import 'package:pretty_dio_logger/pretty_dio_logger.dart'; import '../data/dtos/cocktailss_dto.dart'; import 'api_interface.dart'; class CocktailRepository extends ApiInterface { static final Dio _dio = Dio() ..interceptors.add(PrettyDioLogger( requestHeader: true, requestBody: true, )); static const String _baseUrl = 'https://www.thecocktaildb.com/api/json/v1/1'; @override Future?> loadData(String? q) async { try { final String url = q != null ? '$_baseUrl/search.php?s=$q' // Поиск по названию : '$_baseUrl/filter.php?c=Ordinary_Drink'; // Получение списка коктейлей по категории final Response response = await _dio.get>(url); final CocktailssDto dto = CocktailssDto.fromJson(response.data as Map); final List? data = dto.drinks?.map((e) => e.toDomain()).toList(); return data; } on DioException catch (e) { return null; } } }