process has started

This commit is contained in:
Вера 2024-12-19 11:41:08 +04:00
parent 53ab91afde
commit 68d10dfbe5
3 changed files with 17 additions and 12 deletions

View File

@ -1,10 +1,10 @@
import 'package:json_annotation/json_annotation.dart';
part 'recipe_dto.g.dart';
part 'recipes_dto.g.dart';
@JsonSerializable(createToJson: false)
class RecipesDto {
final List<RecipeDataDto>? hits; // API возвращает список рецептов под ключом "hits".
final List<RecipeDataDto>? hits;
const RecipesDto({this.hits});
@ -14,7 +14,7 @@ class RecipesDto {
@JsonSerializable(createToJson: false)
class RecipeDataDto {
final RecipeAttributesDataDto? recipe; // API возвращает объект "recipe" внутри каждого "hit".
final RecipeAttributesDataDto? recipe;
const RecipeDataDto({this.recipe});
@ -25,7 +25,7 @@ class RecipeDataDto {
@JsonSerializable(createToJson: false)
class RecipeAttributesDataDto {
final String? label;
final double? calories; // API возвращает "calories" как число.
final double? calories;
final String? url;
final String? image;

View File

@ -5,7 +5,7 @@ import 'package:leonteva_pmu/data/repositories/api_interface.dart';
import 'package:leonteva_pmu/domain/models/card.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
class PotterRepository extends ApiInterface {
class RecipeRepository extends ApiInterface {
static final Dio _dio = Dio()
..interceptors.add(PrettyDioLogger(
requestHeader: true,
@ -16,8 +16,8 @@ class PotterRepository extends ApiInterface {
));
static const String _baseUrl = 'https://api.edamam.com';
static const String _appId = '<YOUR_APP_ID>'; // Укажите ваш APP_ID.
static const String _appKey = '<YOUR_APP_KEY>'; // Укажите ваш APP_KEY.
static const String _appId = '<d683b7dc>'; // Укажите ваш APP_ID.
static const String _appKey = '<988fcbbd552b83ca870efced716389e4>'; // Укажите ваш APP_KEY.
@override
Future<List<CardData>?> loadData({String? q, OnErrorCallback? onError}) async {
@ -28,8 +28,8 @@ class PotterRepository extends ApiInterface {
url,
queryParameters: {
'q': q ?? '', // Параметр запроса для поиска рецептов.
'app_id': _appId,
'app_key': _appKey,
'd683b7dc': _appId,
'988fcbbd552b83ca870efced716389e4': _appKey,
},
);

View File

@ -34,12 +34,17 @@ class _BodyState extends State<Body> {
final searchController = TextEditingController();
late Future<List<CardData>?> data;
final repo = PotterRepository();
final repo = RecipeRepository();
@override
void initState() {
data = repo.loadData(onError: (e) => showErrorDialog(context, error: e));
super.initState();
const String query = 'default_query'; // Укажите поисковый запрос по умолчанию
// Загружаем данные с обработкой ошибок
data = repo.loadData(
q: query,
onError: (e) => showErrorDialog(context, error: e),
);
}
@override