Pass a function with parameters to a VoidCallback

后端 未结 7 1738
情书的邮戳
情书的邮戳 2021-01-30 10:22

Is it possible to pass a Function with parameters to a VoidCallback?

for example something like this:

class MyClass {
  void doSomething(int i){

  }

           


        
相关标签:
7条回答
  • 2021-01-30 11:27

    Just replace VoidCallback with Function(int)

    class MyClass {
      void doSomething(int i){
    
      }
    
      MyOtherClass myOtherClass = new MyOtherClass(doSomething);
    }
    
    
    class MyOtherClass {
     //OP code (does not work): final VoidCallback callback(int); 
     final Function(int) callback;
    
      MyOtherClass(this.callback);
    
      callback(5);
    }
    
    0 讨论(0)
提交回复
热议问题