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 '../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() {
|
||||||
|
@ -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(
|
|
||||||
drink['strDrink'], // Название коктейля
|
|
||||||
article: drink['idDrink'], // ID коктейля
|
|
||||||
imageUrl: drink['strDrinkThumb'], // Фото коктейля
|
|
||||||
);
|
|
||||||
}).toList();
|
|
||||||
return data;
|
return data;
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user