问:Flutter如何从类中的参数获取值

时间:2019-03-27 09:10:31

标签: firebase push-notification notifications flutter firebase-cloud-messaging

我是android和flutter开发的新手,我想问一些有关推送通知的问题,我自己构建了firebase_messaging,因为它不支持大通知图像

问题是我无法获得_url

  int _selectedTab = 1;
  static String _url = "";
  static const platform =
      const MethodChannel('com.example.loop_app_flutter_v2');

  @override
  Future<void> _firebaseMessageListener() async {
    String getRedirect;
    String url;
    try {
      final String result =
          await platform.invokeMethod('getFirebaseMessagePayload');
      getRedirect = '$result';
      Map<String, dynamic> notif = jsonDecode(getRedirect);
      url = notif["url"]; //payload success and url show up

    } on PlatformException catch (e) {
      getRedirect = "Failed : '${e.message}'.";
    }
    this.loadNotificationData(getRedirect);
    setState(() {
      _url = url; // i want to assign url to _url and put in List Widget
      print(url); //print show up url
    });
  }


  @override
  void initState() {
    _firebaseMessageListener();
}

  final List<Widget> _children = [
    new MainArtikel(),
    new Webpage(url: _url),
    new FeedBack(),
    new Setting()
  ];


0 个答案:

没有答案