Home > Blockchain >  2 function in onPressed
2 function in onPressed

Time:02-03

I am very new to Flutter and I want to put 2 function on onPressed button.

I try this

ElevatedButton(
     onPressed: () {isConnected ? () =>_sendMessage('1') : null; checkBiometric();},
     child: Text('ON'),
),

but only the checkBiometric is working.

Edit: checkBiometric must be satisfied first before isConnected ? () =>_sendMessage('1') : null to execute.

Please help.

CodePudding user response:

You need to await to complete the first one. Do it like this,

ElevatedButton(
     onPressed: () async {
     await checkBiometric();
     if(isConnected) _sendMessage('1');     
   },

Doing isConnected ? () =>_sendMessage('1') creates another nested anonymous function.

More about Asynchronous programming.

CodePudding user response:

Try formatting it like this-

ElevatedButton(
     onPressed: () { 
     checkBiometric();
     if (isConnected){
      _sendMessage("1");
      }
     
      }
     child: Text('ON'),
),
  •  Tags:  
  • Related