Home > Net >  how to disable elevatedbutton based on the api response in flutter?
how to disable elevatedbutton based on the api response in flutter?

Time:07-06

I am new in flutter and can someone tell me how to enable/disable elevatedbutton based on the API response. I need to know for my project. Thank you

CodePudding user response:

you follow this rule

If onPressed and onLongPress callbacks are null, then the button will be disabled.

ohk new answer is here

suppose your response varibale name is Map<dynamic,dynamic> temp so code is below


Column(
children:[
.
.
.
ElevatedButton(
onPressed:temp['result']=='OUT'?null:(){
//implement your code
},
child:Text("IN")
)
.
.
.
ElevatedButton(
onPressed:temp['result']=='IN'?null:(){
//Implement your code
},
child:Text("OUT")
)

]


)

CodePudding user response:

If the result (condition) of the API response is true, it is activated, if it is false, it is deactivated.

ElevatedButton(
  onPressed: yourApiResponsResult ? (){ implement your code } : null,
  child: Text('ElevatedButton'),
),
  • Related