我的代码看起来像这样
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'),on@R_403_4848@: () { 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 dialogsNavigator.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);});}@overrIDeWidget 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中实现推送通知所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)