- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 269字
- 2021-07-09 18:56:30
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:

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

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.
- .NET之美:.NET關鍵技術深入解析
- Spring Boot開發與測試實戰
- 零基礎學C++程序設計
- Learning AndEngine
- 編譯系統透視:圖解編譯原理
- 琢石成器:Windows環境下32位匯編語言程序設計
- R Deep Learning Cookbook
- Creating Stunning Dashboards with QlikView
- Raspberry Pi Robotic Projects(Third Edition)
- App Inventor少兒趣味編程動手做
- Scala編程實戰
- Mastering Gephi Network Visualization
- Mudbox 2013 Cookbook
- 交互設計師成長手冊:從零開始學交互
- FusionCharts Beginner’s Guide:The Official Guide for FusionCharts Suite