From cb8c65bec17f2c8906c66cfb867a5bebef8b19ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Elias=20M=C3=BCller?= <elias@elias-mueller.com>
Date: Mon, 12 Feb 2024 14:11:56 +0100
Subject: [PATCH] Added throttle on refetch queries on AppLifecycleChange

---
 lib/app.dart | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/app.dart b/lib/app.dart
index c25ae56..5085e54 100644
--- a/lib/app.dart
+++ b/lib/app.dart
@@ -2,6 +2,7 @@
 import 'dart:async';
 import 'dart:developer';
 
+import 'package:easy_debounce/easy_throttle.dart';
 import 'package:firebase_messaging/firebase_messaging.dart';
 import 'package:flutter/material.dart';
 import 'package:persistent_bottom_nav_bar_v2/persistent-tab-view.dart';
@@ -41,8 +42,15 @@ class _AppState extends State<App> with WidgetsBindingObserver {
     log("AppLifecycle: ${state.toString()}");
 
     if(state == AppLifecycleState.resumed) {
-      NotificationTasks.updateProviders(context);
-      Provider.of<TimetableProps>(context, listen: false).run();
+      EasyThrottle.throttle(
+        "appLifecycleState",
+        const Duration(seconds: 10),
+        () {
+          log("Refreshing due to LifecycleChange");
+          NotificationTasks.updateProviders(context);
+          Provider.of<TimetableProps>(context, listen: false).run();
+        }
+      );
     }
   }