Pass a function with parameters to a VoidCallback

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

    Example in UI case. You may need create widget and pass click function.

    1.Create widget with function as paramiter in constructor.

    Container _cardButton({
      Function onClickAction,
    }) {
      return Container(
        width: 340,
        height: 90,
        child: InkWell(
          splashColor: Colors.blue.withAlpha(30),
          onTap: () {
            onClickAction();
          },
          child: Card(
            elevation: 5,
            child: somechild,
          ),
        ),
      );
    

    2. Implement widget to the three view and pass function like this

    _cardButton(
        onClickAction: () => {debugPrint("CLICKED")},
    ),
    

提交回复
热议问题