我遇到了一个问题,从showDialogue()调用Navigator.pop()两次导致屏幕空白.我正在使用Auto_Router包.我该如何解决这个问题?
PopScope widget
PopScope(
canPop: false,
onPopInvoked: (didPop) {
log('on click back button ${MainApp.router.stack.toList()}');
log('didPop: $didPop');
if (didPop) {
log('after pop ${MainApp.router.stack.toList()}');
return;
}
_showBackDialog();
},
showbackdialog function
void _showBackDialog() {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
alignment: Alignment.bottomCenter,
title: const Text('Are you sure?'),
content: const Text(
'Are you sure you want to leave this page?',
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('Nevermind'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('Leave'),
onPressed: () async {
Navigator.pop(context);
Navigator.pop(context);
},
),
],
);
},
);
}
即使堆栈路径为空,路径也会继续弹出而不是退出应用程序.