addToWatched method
- Movie movie
Adds a movie to the watched list.
Implementation
Future<void> addToWatched(Movie movie) async {
// If watchedListId is null, try to initialise it first.
if (_watchedListId == null) {
await _retryInitializeMovieListIds();
}
if (_watchedListId != null) {
final success =
await _movieListService.addMovieToList(_watchedListId!, movie);
if (success) {
// Update stream with fresh data from MovieList.
final movies = await getWatched(forceRefresh: true);
_watchedController.add(movies);
// Create/update the movie file to ensure it exists.
await _createOrUpdateMovieFile(movie);
return;
} else {
debugPrint('❌ Failed to add ${movie.title} to Watched MovieList');
}
} else {
debugPrint('❌ Watched list ID is null, cannot add movie to MovieList');
}
// Fallback to old system if MovieList fails.
final watched = await getWatched();
if (!watched.any((m) => m.id == movie.id)) {
watched.add(movie);
await _saveWatchedToPod(watched);
_watchedController.add(watched);
}
// Create/update the movie file to ensure it exists.
await _createOrUpdateMovieFile(movie);
// Force refresh cache for UI updates.
_cachedWatched = null;
}