Flutter   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了dart – 如何在flutter中实现推送通知大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我正在尝试实施推送通知,如何显示通知可以任何一个帮助,我能听,因为我收到通知我无法看到消息,它出现作为警报,但我想作为通知可以任何一个帮助,在 Android或iOS中我们应该在清单文件和应用程序委托文件中如何在颤动

我的代码看起来像这样

class PushmessagingExample extends StatefulWidget {
 @override
 _PushmessagingExampleState createState() => new _PushmessagingExampleState();
 }

class _PushmessagingExampleState extends State<PushmessagingExample> {
String _homeScreentext = "WaiTing for token...";
bool _topicButtonsDisabled = false;

final Firebasemessaging _firebasemessaging = new Firebasemessaging();
final TextEdiTingController _topicController =
new TextEdiTingController(text: 'topic');

Future<Null> _showItemDialog(Map<String,dynamic> messagE) async {
final Item item = _itemFormessage(messagE);
showDialog<Null>(
    context: context,child: new AlertDialog(
      content: new Text("Item ${messagE} has been updated"),actions: <Widget>[
        new FlatButton(
            child: const Text('CLOSE'),onPressed: () {
              Navigator.pop(context,falsE);
            }),new FlatButton(
            child: const Text('SHOW'),truE);
            }),],)).then((bool shouldNavigatE) {
  if (shouldNavigate == truE) {
    _navigateToItemDetail(messagE);
  }
});
}

 Future<Null> _navigateToItemDetail(Map<String,dynamic> messagE) async     {
final Item item = _itemFormessage(messagE);
// Clear away dialogs
Navigator.popUntil(context,(Route<dynamic> routE) => route is PageRoutE);
if (!item.route.isCurrent) {
  Navigator.push(context,item.routE);
}
}

  @override
 void initState() {
  super.initState();
_firebasemessaging.configure(
  onmessage: (Map<String,dynamic> messagE) {
    print("onmessage: $message");
    print(messagE);
    _showItemDialog(messagE);
  },onLaunch: (Map<String,dynamic> messagE) {
    print("onLaunch: $message");
    print(messagE);
    _navigateToItemDetail(messagE);
  },onResume: (Map<String,dynamic> messagE) {
    print("onResume: $message");
    print(messagE);
    _navigateToItemDetail(messagE);
  },);
_firebasemessaging.requestNotificationPermissions(
    const IosnotificationSetTings(sound: true,badge: true,alert: truE));
_firebasemessaging.onIosSetTingsRegistered
    .listen((IosnotificationSetTings setTings) {
  print("SetTings registered: $setTings");
});
_firebasemessaging.getToken().then((String token) {
  assert(token != null);
  setState(() {
    _homeScreentext = "Push messaging token: $token";
  });
  print(_homeScreentext);
});
}

@override
Widget build(BuildContext context) {
return new Scaffold(


    body: new Material(
      child: new column(
        children: <Widget>[
          new Center(
            child: new Text(_homeScreentext),),));
  }

  }

解决方法

如果您尝试将消息放在锁定屏幕上,请确保您发送的是“通知”消息类型,而不是将传递给正在运行的应用程序的“数据”消息.您可以在Firebase开发人员指南中了解有关 different types of Firebase messages的更多信息.

大佬总结

以上是大佬教程为你收集整理的dart – 如何在flutter中实现推送通知全部内容,希望文章能够帮你解决dart – 如何在flutter中实现推送通知所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。