Skip to content

Instantly share code, notes, and snippets.

@vbalagovic
Created November 28, 2024 17:33
Show Gist options
  • Save vbalagovic/efdd5c018c9f631c8a241df380d41c74 to your computer and use it in GitHub Desktop.
Save vbalagovic/efdd5c018c9f631c8a241df380d41c74 to your computer and use it in GitHub Desktop.
@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