Why can't CupertinoDialog pop when Navigator.pop(context) is called together with a function using a global key?
final GlobalKey <_PlayyButtonState>_playingButtonState = GlobalKey<_PlayyButtonState>();
...
Future<void> showAlert(){
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
title: const Text('Re-write?'),
content: const Text('Are you sure? You will have to write from scratch.'),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
child: const Text('Re-write',
style: TextStyle(
color: Colors.red
)
),
isDestructiveAction: true,
onPressed: () {
_playingButtonState.currentState._onToggle();
Navigator.pop(context); <---- does not pop after calling the function above
},
)
],
),
);
}
}
Removing the code
_playingButtonState.currentState._onToggle();
allow the CupertinoDialog to pop again