I am working a FLUTTER project and need to write a method (or maybe a function). One of the parameters in the method needs to be an expression like:
PlayList videos = videoList[index] as PlayList
Is it possible? If so what type should I should use.
CodePudding user response:
You can achieve what you want, by doing this
void sampleMethod(int playlistIndex){
PlayList videos = videoList[playlistIndex] as PlayList;
// do something with videos
}
Passing PlayList videos = videoList[index] as PlayList
directly as parameter is not possible because, in Dart default values of optional parameters must be constants.
In your case, the value of videos depends on [index]
which is a changing value.
CodePudding user response:
typedef ProcessCallback = PlayList Function(dynamic, int);
class PlayList {
String? id;
PlayList(this.id);
}