addSong method

void addSong({
  1. required Song newSong,
  2. bool verbose = true,
  3. bool includeFeatures = false,
})

Adds a song to the Artist.

This method adds a new song to the artist object. It checks if the song is already in artist's songs and whether the song's artist is the same as the Artist object.

Implementation

void addSong(
    {required Song newSong,
    bool verbose = true,
    bool includeFeatures = false}) {
  if (newSong.title != null) {
    if (_songs.any((element) => element.title! == newSong.title)) {
      if (verbose) {
        print('${newSong.title} already in $name, not adding song.');
      }
    }

    if (name != null || newSong.artist != null) {
      if (newSong.artist == name ||
          (includeFeatures && newSong.featuredArtists.contains(name))) {
        _songs.add(newSong);
        ++_numSongs;
        if (verbose) {
          print('Song $_numSongs: ${newSong.title}');
        }
      }
    }
  } else {
    if (verbose) {
      print("Can't add song by ${newSong.artist}, artist must be $name.");
    }
  }
}