官术网_书友最值得收藏!

Notifying the user of an update

However impressive a created display is it is unlikely to hold the user's attention forever and they are likely to switch to another application or browser tab. Luckily, HTML5 has a feature that will allow notifications on the desktop.

The main.dart function quakeUpdate checks if there is a significant update to notify the user about. To determine which item in the list to notify the user about, the lastWhere method is used. This List method finds the last item in the list that matches the criteria defined by the supplied function. In this case, we look at each feature's magnitude value (stored in gf[2]) and return true or false if the value meets the threshold:

quakeUpdate([Timer t = null]) async {
  await featPlotter.updateData();
  featPlotter.updateHotspots();
  quakeMap.drawMapGrid();

  List notiFeature =
      featPlotter.geoFeatures.lastWhere((List gf) => gf[2] > 1.9);

  String permResult = await Notification.requestPermission();
  if (permResult == 'granted') {
    Notification notifyQuake = new Notification('Quake Alert',
        body: 'Quake Update ${notiFeature[3]} - ${notiFeature[2]}');
  }
}

As this feature is potentially intrusive to a user's computer, the web page must ask for permission to show alerts. In Dartium, a prompt is shown at the top of the page requiring a yes or no response:

Notifying the user of an update

Once permission has been granted, the final step is to create an instance of the notification class. No further method call is required:

Notifying the user of an update

The application is set to notify quite often—you may wish to raise the level at which quakes are notified or you will find yourself dismissing a lot of notifications. The visual display of the notification may vary on different platforms and web browsers.

主站蜘蛛池模板: 毕节市| 滕州市| 阿图什市| 章丘市| 库车县| 肃宁县| 和政县| 新河县| 恩平市| 抚松县| 洛南县| 法库县| 政和县| 沅江市| 察隅县| 迁西县| 射阳县| 炎陵县| 深圳市| 九龙县| 习水县| 晋城| 谷城县| 武汉市| 岳西县| 西贡区| 施秉县| 衡东县| 巴林右旗| 陵水| 开阳县| 美姑县| 淮滨县| 科尔| 安吉县| 雅安市| 屯留县| 巴林左旗| 崇左市| 鄂伦春自治旗| 库尔勒市|