How Flutter dynamically controls the barrierDismissible of showDialog
I am developing Flutter and want to implement a dialog that can be closed by clicking on the background when it pops up by default. When clicking on the button in the dialog box, a time-consuming operation will be performed. At this time, the click background needs to be set as non closable. After the time-consuming operation is completed, the click background needs to be set as closable. However, I found that methods such as showDialog or showGeneralDialog have static barriers that cannot be dynamically controlled. How can I implement this?
bool canClose = true;
showDialog(
context: context,
barrierDismissible: canClose,
builder: (buildContext) {
return Dialog(
child: Container(
width: 300,
height: 300,
color: Colors.red,
child: Column(
children: [
Container(
height: 150,
color: Colors.blue,
child: TextButton(
onPressed: () {
canClose = false;
},
child: Text('Prohibit clicking on background to close'),
),
),
Container(
height: 150,
color: Colors.green,
child: TextButton(
onPressed: () {
canClose = true;
},
child: Text('You can click on the background to close it'),
),
)
],
),
),
);
},
);