Pass a function with parameters to a VoidCallback

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

    1) Create typedef first in any constant class:

    typedef StringVoidFunc = void Function(String);
    

    2) Pass from calling function class one

    showAlertDialog(doSomething);
    

    3) Call back handle Function

    void doSomething(String i){
    Navigator.pop(context);
    setState(() {
    
    });
    

    }

    4) From where you want to fire call back from Class Two

        showAlertDialog(StringVoidFunc callback) {
         callback("delete");
    }
    

提交回复
热议问题