有什么办法可以使用flutter更改Webview中来自通知的链接吗?

时间:2020-09-14 16:16:17

标签: firebase flutter dart webview firebase-cloud-messaging

我在Flutter应用中使用了Webview小部件,我想更改并打开一个 用户点击通知时链接,该链接是静态的,因为我测试了 这,我试图做到这一点,但它对我的代码不起作用:

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  dynamic url = "https://google.com";
  final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  @override
  void initState() {
    configureCallBacks();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: WebViewScaffold(
      Url: url,
    ));
  }

这是通知代码

  void configureCallBacks() {
    _firebaseMessaging.configure(
      onMessage: (message) async {
        // running when user open the app
        print('onMessage :$message ');
        setState(() {
          url = 'https://youtube.com';
        });
      },
      onResume: (message) async {
        String data = message['data']['ali'];
        print('onResume : $data');
          url = 'https://facebook.com';
      },
      onLaunch: (message) async {
        print('onLaunch : $message');
        setState(() {
          url = 'https://twitter.com';
        });
      }, 
    );
  }
}

0 个答案:

没有答案