hasMovieFile method
- Movie movie
Checks if a movie file exists (i.e., user has interacted with this movie).
Implementation
Future<bool> hasMovieFile(Movie movie) async {
// First check our cache.
if (_moviesWithFiles.contains(movie.id)) {
return true;
}
// Try to read the file to see if it exists.
final movieData = await _readMovieFile(movie);
if (movieData != null) {
final hasRating = movieData['rating'] != null;
final hasComment = movieData['comment'] != null &&
(movieData['comment'] as String?)?.isNotEmpty == true;
if (hasRating || hasComment) {
// Add to cache since we found the file exists.
_moviesWithFiles.add(movie.id);
// Also populate our data caches.
if (hasRating && movieData['rating'] is double) {
_cachedRatings ??= {};
_cachedRatings![movie.id.toString()] = movieData['rating'] as double;
}
if (hasComment && movieData['comment'] is String) {
_cachedComments ??= {};
_cachedComments![movie.id.toString()] =
movieData['comment'] as String;
}
return true;
}
}
return false;
}