显示从 Firebase Cloud Messaging 控制台到 Flutter 应用程序的自定义数据?

Display Custom Data from Firebase Cloud Messaging console to Flutter app?

您好,有什么方法可以使用我在 Firebase Cloud Messaging 控制台中设置的 keyvalueAdditional Options 将推送通知显示在我的 Flutter 应用中?

我很难完成这项工作,例如,我在我的 FCM 控制台中使用 url 作为键,使用 link 作为我的值。

What I exactly want is like this: When I send a push notification, it display to a custom screen/url_launcher/widget within my app and that screen/url_launcher/widget shows the data I've inputted in FCM console using the KEY and VALUE that I've set when sending the push notification.

问题是如何在我的应用程序中显示这些数据?我如何使用这些键和值? 我有点不知道如何编码

下面是我的代码:

import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();


@override
void initState() {
  super.initState();
  firebaseCloudMessagingListeners();
}
void firebaseCloudMessagingListeners() {
  if (Platform.isIOS) iOSPermission();

  _firebaseMessaging.getToken().then((token){
    print(token);
  });

  _firebaseMessaging.configure(
    onMessage: (Map<String, dynamic> message) async {
      print('on message $message');

    },
    onResume: (Map<String, dynamic> message) async {
      print('on resume $message');
    },
    onLaunch: (Map<String, dynamic> message) async {
      print('on launch $message');
    },
  );
}

void iOSPermission() {
  _firebaseMessaging.requestNotificationPermissions(
      IosNotificationSettings(sound: true, badge: true, alert: true)
  );
  _firebaseMessaging.onIosSettingsRegistered
      .listen((IosNotificationSettings settings)
  {
    print("Settings registered: $settings");
  });
}



  WebViewController _myController;
      final Completer<WebViewController> _controller =
      Completer<WebViewController>();
  @override
  Widget build(BuildContext context) {
    return SafeArea(
            child: Scaffold(
                  body: WebView(
                  initialUrl: 'https://syncshop.online/en/',
                  javascriptMode: JavascriptMode.unrestricted,
                  onWebViewCreated: (controller) {
                  _controller.complete(controller);
                },
          onPageFinished: (controller) async {
          (await _controller.future).evaluateJavascript("document.getElementsByClassName('footer-container')[0].style.display='none';");
            (await _controller.future).evaluateJavascript("document.getElementById('st_notification_1').style.display='none';");
            (await _controller.future).evaluateJavascript("document.getElementById('sidebar_box').style.display='none';");
          },
          ),
    floatingActionButton: FutureBuilder<WebViewController>(
        future: _controller.future,
        builder: (BuildContext context, AsyncSnapshot<WebViewController> controller) {
          if (controller.hasData) {
            return FloatingActionButton(
            onPressed: () {
              controller.data.reload();
            },
            child: Icon(Icons.refresh),
          );
          }
          return Container();
        }
        ),
          ),
      );
    }
}

这是从控制台发送自定义数据的方式,

您可以收到这样的通知,

   _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("$message");

输出

{notification: {title: rrakkk, body: wer}, data: {url: Whosebug}}

如何从上面获取 url 值?

 print("${message['data']['url']}");

输出

Whosebug