I have a class named Track, which holds the title, author and other basic details of a music track, and also a class named Library which is supposed to work with the Track class and manage all the tracks, add new ones, remove etc, now the problem is when I'm trying to invoke the method addTrack of an object of the class Library, I'm getting the error "missing function parameters" when I am already passing in a track object to the method.

I am stuck on this, I tried googling about classes and came across a few examples but in those too the method invocation is not working, giving the same error, I tried running the code in dartpad, and also in the flutter SDK, both don't seem to work.

Here is the code,

class Track {
  var author, duration, image, title;

  Track({this.title, this.author, this.duration, this.image});
}

class Library {
    List<Track> tracks = [];

    void addTrack(Track t) {
      tracks.add(t);
    }
}

final music =  Library();

Track t = new Track( title: "hi");

music.addTrack(t);


Solution 1: Christopher Moore

There needs to be a main method somewhere. I wrapped the bottom three lines with main and your code works fine.

void main() {
  final music = Library();
  Track t = new Track( title: "hi");
  music.addTrack(t);
}