Flutter报错“Failed assertion: line 5139 pos 12: ‘!_debugLocked’: is not true.”
详细信息如下:
Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5139 pos 12: '!_debugLocked': is not true.
我的实际场景是点击事件中需要按照先后顺序弹出两个Dialog,如果这样写:
onTap:() async {
await _showDialogA();
await _showDialogB();
}
在某些场景下确实是按照先后顺序,但在我这个实际项目中,会出现同时弹出的情况,只好这样写:
onTap:(){
await _showDialogA();
}
Future<void> _showDialogA(){
DialogA.showDialog(callListener:CallBackListener(
callBack:(){
//DialogA的回调方法中,再调用DialogB
_showDialogB();
}
));
}
这时会出现上面错误信息,解决办法是在_showDialogB()外面包一层
Future.delayed(Duration.zero, () {
});
修改后的代码如下:
onTap:(){
await _showDialogA();
}
Future<void> _showDialogA(){
DialogA.showDialog(callListener:CallBackListener(
callBack:(){
//DialogA的回调方法中,再调用DialogB
Future.delayed(Duration.zero, () {
_showDialogB();
});
}
));
}