I\'m trying to access a class value by using a variable previously defined in dart, but I keep getting the error the operator [] isn\'t defined for the class
You cannot access class members by a string containing their name. (Except with mirrors - outside the scope of this answer.)
You could remove the class altogether and just use a Map
.
Map movie = {
'movieTitle': 'Toy Story',
'actor': 'Tom Hanks',
}
You could add some bool
methods on the class.
bool hasNoActor() => actor == null;
...
List values = movieList.where((m) => !m.hasNoActor()).toList();
Or, you could pass a lambda to your mapper.
Movie movieTitle = Movie()
..name = 'Toy Story'
..actor = 'Tom Hanks';
Function hasActor = (Movie m) => m.actor != null;
List values = movieList.where(hasActor).toList();