'Flutter callback / passing function as a parameter problem

I'm trying to pass a function as a parameter. My code runs but the function doesn't fire.

I have a Holiday class

  final VoidCallback callback;
  Holiday(this.holidayStart, this.holidayEnd, this.holidayDuration, this.callback);

Inside the Holiday class I have a function to build a widget with a button. here I use...

   onPressed: () {
       callback;
   },

In my main.dart file when I create a new instance of Holiday I pass a function like this....

holidays.add(Holiday(startSelected, endSelected, stay, () { print('pressed'); }))

Everything compiles fine but pressed is never printed. Any ideas what I'm doing wrong here?

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source