4-5 labs
This commit is contained in:
parent
36efeceab0
commit
25cc6e6257
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user