Pass a function with parameters to a VoidCallback

后端 未结 7 1889
情书的邮戳
情书的邮戳 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:07

    Instead of VoidCallback, you can use ValueChanged, here is an example:

    class MyClass {
      static void doSomething(int i) {}
    
      MyOtherClass myOtherClass = MyOtherClass(doSomething);
    }
    
    class MyOtherClass {
      final ValueChanged callback;
    
      MyOtherClass(this.callback);
    }
    

    You can then call callback with any int value

    callback(10);
    

提交回复
热议问题