process has started
This commit is contained in:
parent
53ab91afde
commit
68d10dfbe5
@ -1,10 +1,10 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
part 'recipe_dto.g.dart';
|
part 'recipes_dto.g.dart';
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
class RecipesDto {
|
class RecipesDto {
|
||||||
final List<RecipeDataDto>? hits; // API возвращает список рецептов под ключом "hits".
|
final List<RecipeDataDto>? hits;
|
||||||
|
|
||||||
const RecipesDto({this.hits});
|
const RecipesDto({this.hits});
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ class RecipesDto {
|
|||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
class RecipeDataDto {
|
class RecipeDataDto {
|
||||||
final RecipeAttributesDataDto? recipe; // API возвращает объект "recipe" внутри каждого "hit".
|
final RecipeAttributesDataDto? recipe;
|
||||||
|
|
||||||
const RecipeDataDto({this.recipe});
|
const RecipeDataDto({this.recipe});
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ class RecipeDataDto {
|
|||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
class RecipeAttributesDataDto {
|
class RecipeAttributesDataDto {
|
||||||
final String? label;
|
final String? label;
|
||||||
final double? calories; // API возвращает "calories" как число.
|
final double? calories;
|
||||||
final String? url;
|
final String? url;
|
||||||
final String? image;
|
final String? image;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import 'package:leonteva_pmu/data/repositories/api_interface.dart';
|
|||||||
import 'package:leonteva_pmu/domain/models/card.dart';
|
import 'package:leonteva_pmu/domain/models/card.dart';
|
||||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||||
|
|
||||||
class PotterRepository extends ApiInterface {
|
class RecipeRepository extends ApiInterface {
|
||||||
static final Dio _dio = Dio()
|
static final Dio _dio = Dio()
|
||||||
..interceptors.add(PrettyDioLogger(
|
..interceptors.add(PrettyDioLogger(
|
||||||
requestHeader: true,
|
requestHeader: true,
|
||||||
@ -16,8 +16,8 @@ class PotterRepository extends ApiInterface {
|
|||||||
));
|
));
|
||||||
|
|
||||||
static const String _baseUrl = 'https://api.edamam.com';
|
static const String _baseUrl = 'https://api.edamam.com';
|
||||||
static const String _appId = '<YOUR_APP_ID>'; // Укажите ваш APP_ID.
|
static const String _appId = '<d683b7dc>'; // Укажите ваш APP_ID.
|
||||||
static const String _appKey = '<YOUR_APP_KEY>'; // Укажите ваш APP_KEY.
|
static const String _appKey = '<988fcbbd552b83ca870efced716389e4>'; // Укажите ваш APP_KEY.
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<CardData>?> loadData({String? q, OnErrorCallback? onError}) async {
|
Future<List<CardData>?> loadData({String? q, OnErrorCallback? onError}) async {
|
||||||
@ -28,8 +28,8 @@ class PotterRepository extends ApiInterface {
|
|||||||
url,
|
url,
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'q': q ?? '', // Параметр запроса для поиска рецептов.
|
'q': q ?? '', // Параметр запроса для поиска рецептов.
|
||||||
'app_id': _appId,
|
'd683b7dc': _appId,
|
||||||
'app_key': _appKey,
|
'988fcbbd552b83ca870efced716389e4': _appKey,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -34,12 +34,17 @@ class _BodyState extends State<Body> {
|
|||||||
final searchController = TextEditingController();
|
final searchController = TextEditingController();
|
||||||
late Future<List<CardData>?> data;
|
late Future<List<CardData>?> data;
|
||||||
|
|
||||||
final repo = PotterRepository();
|
final repo = RecipeRepository();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
data = repo.loadData(onError: (e) => showErrorDialog(context, error: e));
|
const String query = 'default_query'; // Укажите поисковый запрос по умолчанию
|
||||||
super.initState();
|
|
||||||
|
// Загружаем данные с обработкой ошибок
|
||||||
|
data = repo.loadData(
|
||||||
|
q: query,
|
||||||
|
onError: (e) => showErrorDialog(context, error: e),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user