getOrCreateStandardMovieList method
- String listType
Gets or creates a standard MovieList (e.g. "to_watch", "watched").
Implementation
Future<String?> getOrCreateStandardMovieList(String listType) async {
try {
final displayName = listType
.replaceAll('_', ' ')
.split(' ')
.map((word) =>
word.isEmpty ? '' : word[0].toUpperCase() + word.substring(1))
.join(' ');
// Scan the user_lists directory for existing MovieLists instead of relying on profile data.
final existingMovieListId =
await _findExistingMovieListInDirectory(listType, displayName);
if (existingMovieListId != null) {
return existingMovieListId;
}
// Generate appropriate description for standard lists.
String description;
switch (listType) {
case 'to_watch':
description = 'List of movies you want to watch';
break;
case 'watched':
description = 'List of movies you have watched';
break;
case 'favorites':
description = 'List of your favorite movies';
break;
default:
description = 'List of movies: $displayName';
}
// No existing list found, create a new one.
final listId = await createMovieList(
displayName,
movies: [],
description: description,
);
if (listId == null) {
debugPrint('❌ Failed to create standard movie list: $listType');
}
return listId;
} catch (e) {
debugPrint('❌ Exception in get/create standard movie list: $e');
return null;
}
}