From 25cc6e62575dc7dc9440a34fb87f136ac5e55701 Mon Sep 17 00:00:00 2001 From: Nastya_Kozlova Date: Fri, 1 Nov 2024 18:41:53 +0400 Subject: [PATCH] 4-5 labs --- lib/presentation/home_page/home_page.dart | 4 ++-- lib/repositories/CocktailRepository.dart | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/presentation/home_page/home_page.dart b/lib/presentation/home_page/home_page.dart index ee2933c..cfdc3bb 100644 --- a/lib/presentation/home_page/home_page.dart +++ b/lib/presentation/home_page/home_page.dart @@ -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 { late Future?> data; /*final PotterRepository repo = PotterRepository();*/ final CocktailRepository repo = CocktailRepository(); + /*final MockRepository repo = MockRepository();*/ + @override void initState() { diff --git a/lib/repositories/CocktailRepository.dart b/lib/repositories/CocktailRepository.dart index 0b4a76c..1b21697 100644 --- a/lib/repositories/CocktailRepository.dart +++ b/lib/repositories/CocktailRepository.dart @@ -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 response = await _dio.get>(url); - if (response.data != null && response.data['drinks'] != null) { - final List 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); + final List? data = dto.drinks?.map((e) => e.toDomain()).toList(); + return data; } on DioException catch (e) { return null; }