Refactor code structure for improved readability and maintainability
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -12,12 +12,12 @@ class RecipeRepository {
|
||||
|
||||
Future<List<Recipe>> fetchRecipes({String? token}) async {
|
||||
try {
|
||||
final data = await _api.getJson(RecipeApiPaths.list, token: token);
|
||||
final dynamic data = await _api.getJson(RecipeApiPaths.list, token: token);
|
||||
if (data is! List) {
|
||||
throw const ApiException(
|
||||
type: ApiErrorType.unknown, message: 'Ogiltigt svar från servern.');
|
||||
}
|
||||
return data
|
||||
return (data as List)
|
||||
.map((e) => Recipe.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
} on ApiException {
|
||||
|
||||
@@ -21,8 +21,8 @@ class RecipeDetailScreen extends ConsumerWidget {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(recipeAsync.valueOrNull?.title ?? 'Recept'),
|
||||
actions: recipeAsync.valueOrNull == null
|
||||
title: Text(recipeAsync.maybeWhen(data: (d) => d, orElse: () => null)?.title ?? 'Recept'),
|
||||
actions: recipeAsync.maybeWhen(data: (d) => d, orElse: () => null) == null
|
||||
? []
|
||||
: [
|
||||
IconButton(
|
||||
|
||||
Reference in New Issue
Block a user