0

I'm coming from Delphi and the paradigm may be different but I want to do define a custom event handler in Dart, something like the pseudo code below.

// -- I don't know how to define this type...
typedeft TCustomEvent = function (int pParam) of object;

class MyFirstClass {
  TCustomEvent onDoSomething;

  void doIt(int pValue){
    onDoSomething(pValue);
  }
}

class MySecondClass {

  void makeMyFirstClassDoIt(){
    MyFirstClass vObj = MyFirstClass();
    vObj.onDoSomething = doSomething;
    vObj.doIt(5);
  }

  doSomething(int pValue) {
    print(pValue);
  }
}

Any help would be greatly appreciated.

cjmarques
  • 632
  • 1
  • 7
  • 17
  • 1
    Check if this answer https://stackoverflow.com/a/12546025/8745788 suits you needs. More info about [typedefs](https://www.dartlang.org/guides/language/language-tour#typedefs) – Mattia Apr 02 '19 at 19:33
  • That worked perfectly! thank you! – cjmarques Apr 03 '19 at 03:48

0 Answers0