簡體   English   中英

當我的 Flutter 應用程序關閉時,如何更新我的 Firebase 數據?

[英]How can I update my Firebase data when my flutter app closes?

我想在用戶使用完我的應用程序后更新他們的時間數據,如果他們也強行關閉應用程序,我也希望能夠更新數據。 誰能告訴我是否有辦法在關閉應用程序之后或之后運行代碼?

關閉應用程序后我想運行的代碼是這樣的:

endoff_time = DateTime.now();
var date = DateFormat('dd-MM-yyyy').format(DateTime.now());
var startingTime = DateFormat('yyyy-MM-dd – kk:mm').format(startup_time);
var endingTime = DateFormat('yyyy-MM-dd – kk:mm').format(endoff_time);
database_Reference
    .child("users")
    .child(_wifiObject.macAddress)
    .child(date)
    .set({
  "name": userInformation[0].name,
  "router_bssid": userInformation[0].mac_ip,
  "date": date,enter code here
  "startingTime": startingTime,
  "endingTime": endingTime,
  "totalWorkTime": hours,
});

我認為最好的方法是在實時數據庫 sdk 中使用onDisconnect()回調(!不是 firestore!)。 但是使用此解決方案,代碼將位於服務器端...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM