Files
flutter/lib/models/exercises/ingredient_api.dart
Roland Geider faf1018f2a Fixes for flutter typeahead 5.1.0
Also, add some models for the API response from the search
2024-01-29 12:07:26 +01:00

41 lines
1.3 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
part 'ingredient_api.freezed.dart';
part 'ingredient_api.g.dart';
/// Model for the search results returned from the /api/v2/ingredient/search endpoint
@freezed
class IngredientApiSearchDetails with _$IngredientApiSearchDetails {
factory IngredientApiSearchDetails({
required int id,
required String name,
required String? image,
// ignore: invalid_annotation_target
@JsonKey(name: 'image_thumbnail') required String? imageThumbnail,
}) = _IngredientApiSearchDetails;
factory IngredientApiSearchDetails.fromJson(Map<String, dynamic> json) =>
_$IngredientApiSearchDetailsFromJson(json);
}
@freezed
class IngredientApiSearchEntry with _$IngredientApiSearchEntry {
factory IngredientApiSearchEntry({
required String value,
required IngredientApiSearchDetails data,
}) = _IngredientApiSearchEntry;
factory IngredientApiSearchEntry.fromJson(Map<String, dynamic> json) =>
_$IngredientApiSearchEntryFromJson(json);
}
@freezed
class IngredientApiSearch with _$IngredientApiSearch {
factory IngredientApiSearch({
required List<IngredientApiSearchEntry> suggestions,
}) = _IngredientApiSearch;
factory IngredientApiSearch.fromJson(Map<String, dynamic> json) =>
_$IngredientApiSearchFromJson(json);
}