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

View File

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