首页 > 解决方案 > 我们如何在颤动中按下单个按钮执行两个功能

问题描述

RaisedButton(
               color: Colors.blueAccent, 
               onPressed: () =>sendData(); //fun1
               signupPage(context) //fun2
               child: 
                Text("Signup"),
             )

此代码给出错误..预计会找到 ')'

在此处输入图像描述

标签: buttonflutterdart

解决方案


Arrow Function可以运行单语句功能。

选项:

1 - 您可以运行以下两个功能。

RaisedButton(
               color: Colors.blueAccent, 
               onPressed: () {
               sendData(); //fun1
               signupPage(context); //fun2
               },
               child: 
                Text("Signup"),
             )

或者

2 - 您可以在 fun 1 中运行 fun2。

RaisedButton(
               color: Colors.blueAccent, 
               onPressed: () => sendData(context), //fun1
               child: 
                Text("Signup"),
             )

void sendData(BuildContext context){
//sendData Code ...
signupPage(context); //fun2
...
}

推荐阅读