我通过通知打开了应用程序,并希望在用户按下后使其保持打开状态? [英] I open the app through the notification and want to keep it open after the user presses back?

查看:123
本文介绍了我通过通知打开了应用程序,并希望在用户按下后使其保持打开状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序具有使用OneSignal开发的通知系统.

I have an app that has a notification system developed with OneSignal.

用例: -当通知随应用程序关闭而用户单击时,应用程序将直接打开与该通知相对应的屏幕,(直到我得到它!)但是当用户单击返回时,该应用程序将关闭,因为只有那条路上的那条路;

Use case: - When the notification comes with the app closed and the user clicks on it the app directly opens the screen corresponding to that notification, (Until then I got it!) But when the user clicks back, the app is closed, because there is only that route in the pile;

我想以某种方式重新打开该应用程序或使其保持打开状态!

I want to somehow reopen the app or keep it open!

类似于Whatsapp中发生的事情,因为当通过聊天中的直接通知关闭和打开该应用程序时,当它回来时它又关闭并再次使该应用程序打开动画!

Something similar to what happens in Whatsapp, because when the app is closed and opened by direct notification in a chat, when it comes back it closes and makes the app open animation again!

有人可以帮我吗?或至少启发我.谢谢!

Could someone help me with this? Or at least enlighten me. Thanks!

推荐答案

这似乎是WillPopScope小部件的用例.该小部件将告诉您用户是否按下了后退按钮.您只需要用它包裹一下脚手架即可.

That seems like a use case for the WillPopScope widget. this widget will tell you if the user has pressed the back button. you just need to wrap your scaffold with it.

下面是使用方法的示例:

here is an example of how to use it:

class MessagingPage extends StatefulWidget {
  @override
  _MessagingPageState createState() => _MessagingPageState();
}

class _MessagingPageState extends State<MessagingPage> {

  bool hasComeFromNotification = true;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: (){
        if(hasComeFromNotification){
          Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context){
            return HomePage();
          }));
          return Future.value(false); // do not call Navigator.pop() because I already called it
        } else {
          return Future.value(true); // call Navigator.pop()
        }
      },
      child: Scaffold(
        body: Center(
          child: Text('messaging'),
        ),
      ),
    );
  }
}

这篇关于我通过通知打开了应用程序,并希望在用户按下后使其保持打开状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆