implemented scheduled updates for widgets

This commit is contained in:
2025-03-11 15:50:02 +01:00
parent b0bbad7f97
commit 6bbc75fa94
9 changed files with 197 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:developer';
import 'dart:io';
import 'package:background_fetch/background_fetch.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
@@ -17,6 +18,7 @@ import 'package:provider/provider.dart';
import 'api/mhsl/breaker/getBreakers/getBreakersResponse.dart';
import 'app.dart';
import 'background_tasks/scheduledTask.dart';
import 'firebase_options.dart';
import 'model/accountData.dart';
import 'model/accountModel.dart';
@@ -84,6 +86,8 @@ Future<void> main() async {
child: const Main(),
)
);
BackgroundFetch.registerHeadlessTask(ScheduledTask.headless);
}
class Main extends StatefulWidget {
@@ -111,6 +115,7 @@ class _MainState extends State<Main> {
Provider.of<BreakerProps>(context, listen: false).run();
});
ScheduledTask.configure();
super.initState();
}
@@ -146,7 +151,7 @@ class _MainState extends State<Main> {
child: Consumer<AccountModel>(
builder: (context, accountModel, child) {
switch(accountModel.state) {
case AccountModelState.loggedIn: return const App();
case AccountModelState.loggedIn: return App(key: App.appContext);
case AccountModelState.loggedOut: return const Login();
case AccountModelState.undefined: return const PlaceholderView(icon: Icons.timer, text: 'Daten werden geladen');
}