如何解决当我从背景颤动进入前景时,showDialog 不可见
我正在我的 flutter 应用程序上做一个推送通知,在前台和后台处理它。当通知被点击时,我想在网络操作完全加载之前加载一个 dialog
。所以,当我在前台时,对话框显示得很好,但当我从后台进入前台时不会出现。这可能是什么原因?
void showRideOrder(String newOrder) async {
orderIdString = orderId = newOrder;
print("new order here" + orderId);
print("fetching info");
assetsAudioPlayer.open(
Audio('sounds/alert.mp3'),);
assetsAudioPlayer.play();
showDialog( //not showing when coming in from the background
barrierDismissible: false,context: context,builder: (BuildContext builder_context) =>
CustomProgressDialog(status:'Fetching details',),);
Provider.of<MainBloc>(context,listen: false).
fetchRideInfo(context,orderId).then((value){
print("ride order fetched. closing dialog");
Navigator.pop(context);
Navigator.push(
context,MaterialPageRoute(builder: (context) =>
RideRequestPage(orderId: orderId)),);
orderIdString =null;
}).catchError((error) {
Navigator.pop(context);
AlertManager.showToast(error.toString());
});
orderIdString = null;
}
解决方法
我认为是因为什么时候进入前台,方法没有被调用。
尝试使用 WidgetsBindingObserver 扩展类并覆盖
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
showRideOrder(...); //call your function
}
确保你编写 switch case 并在适当的情况下调用它
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。