通过FCM收到通知时触发小吃店

时间:2020-08-27 10:13:38

标签: flutter dart firebase-cloud-messaging

当前,onMessage函数将显示一个AlertDialog。此功能正常工作。

但是,我想在应用程序处于前台时显示小吃栏。

有人有这个例子吗?

我当前的initState:

void initState() {
super.initState();
getCurrentUser();
extractMachineIDs(); //IGNORE
getMachineStatus(0); //IGNORE
_fcm.configure(
  onMessage: (Map<String, dynamic> message) async {
    print("onMessage: $message");
    showDialog(   // I WANT A SNACKBAR HERE INSTEAD
      context: context,
      builder: (context) => AlertDialog(
        content: ListTile(
          title: Text(message['notification']['title']),
          subtitle: Text(message['notification']['body']),
        ),
        actions: <Widget>[
          FlatButton(
            child: Text('DISMISS'),
            onPressed: () => Navigator.of(context).pop(),
          ),
        ],
      ),
    );
  },
  onLaunch: (Map<String, dynamic> message) async {
    print("onLaunch: $message");
  },
  onResume: (Map<String, dynamic> message) async {
    print("onResume: $message");
    Navigator.pushNamed(context, AlertsNotifications.id);
  },
);

}

1 个答案:

答案 0 :(得分:1)

使用它代替const makeTree = (categories, parent) => { const node = {}; categories .filter(c => c.parentId === parent) .forEach(c => { node[c.id] = makeTree(categories, c.id); Object.assign(node[c.id], c); }); return node; } console.log(makeTree(mockData, null));

public ActionResult Index(UserData model)
{
      try
      {
            // Pass the "personlist" object for conversion object to JSON string  
            string jsondata = new JavaScriptSerializer().Serialize(model);
            string path = Server.MapPath("~/App_Data/output.json");
            // Write that JSON to txt file,  
            System.IO.File.WriteAllText(path , jsondata);
            TempData["msg"] = "Json file Generated! check this in your App_Data folder";
      }
      catch (Exception e) { }
            
      return RedirectToAction("Index");
  }