Created
November 28, 2024 17:33
-
-
Save vbalagovic/efdd5c018c9f631c8a241df380d41c74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@riverpod | |
class EditMovie extends _$EditMovie { | |
@override | |
AsyncValue<Movie?> build() => const AsyncValue.data(null); | |
void setMovie(Movie movie) { | |
state = AsyncValue.data(movie); | |
} | |
Future<void> saveChanges(Movie updatedMovie) async { | |
if (state.value == null) return; | |
state = const AsyncValue.loading(); | |
try { | |
await ref.read(movieNotifierProvider.notifier) | |
.updateMovie(updatedMovie.id, updatedMovie.toJson()); | |
state = AsyncValue.data(updatedMovie); | |
} catch (e, st) { | |
state = AsyncValue.error(e, st); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment