This commit is contained in:
Nastya_Kozlova 2024-11-01 18:41:53 +04:00
parent 36efeceab0
commit 25cc6e6257
2 changed files with 7 additions and 13 deletions

View File

@ -8,8 +8,6 @@ import '../../repositories/potter_repository.dart';
import '../details_page/details_page.dart';
import 'package:dio/dio.dart';
part 'card.dart';
@ -54,6 +52,8 @@ class _BodyState extends State<Body> {
late Future<List<CardData>?> data;
/*final PotterRepository repo = PotterRepository();*/
final CocktailRepository repo = CocktailRepository();
/*final MockRepository repo = MockRepository();*/
@override
void initState() {

View File

@ -1,6 +1,8 @@
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 {
@ -21,17 +23,9 @@ class CocktailRepository extends ApiInterface {
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(url);
if (response.data != null && response.data['drinks'] != null) {
final List<CardData> data = (response.data['drinks'] as List).map((drink) {
return CardData(
drink['strDrink'], // Название коктейля
article: drink['idDrink'], // ID коктейля
imageUrl: drink['strDrinkThumb'], // Фото коктейля
);
}).toList();
return data;
}
return null;
final CocktailssDto dto = CocktailssDto.fromJson(response.data as Map<String, dynamic>);
final List<CardData>? data = dto.drinks?.map((e) => e.toDomain()).toList();
return data;
} on DioException catch (e) {
return null;
}