// GCG.MeinCantor - Die Schulplattform für Cantorianer. // Copyright (C) 2021-2022 Georg-Cantor-Gymnasium Halle (Saale) // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . import 'package:flutter/material.dart'; import 'package:meincantor/background_fetch.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:meincantor/dashboard.dart'; import 'package:meincantor/login.dart'; import 'dart:math'; import 'package:background_fetch/background_fetch.dart'; void backgroundFetchHeadlessTask(HeadlessTask task) async { String taskId = task.taskId; bool isTimeout = task.timeout; if (isTimeout) { // This task has exceeded its allowed running-time. // You must stop what you're doing and immediately .finish(taskId) print("[BackgroundFetch] Headless task timed-out: $taskId"); BackgroundFetch.finish(taskId); return; } print('[BackgroundFetch] Headless event received.'); await backgroundFetchTimetable(); await backgroundFetchArticles(); BackgroundFetch.finish(taskId); } void main() async { runApp(const App()); BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); } class App extends StatefulWidget { const App({Key? key}) : super(key: key); @override _AppState createState() => _AppState(); } class _AppState extends State { MaterialColor generateMaterialColor(Color color) { return MaterialColor(color.value, { 50: tintColor(color, 0.5), 100: tintColor(color, 0.4), 200: tintColor(color, 0.3), 300: tintColor(color, 0.2), 400: tintColor(color, 0.1), 500: tintColor(color, 0), 600: tintColor(color, -0.1), 700: tintColor(color, -0.2), 800: tintColor(color, -0.3), 900: tintColor(color, -0.4), }); } int tintValue(int value, double factor) => max(0, min((value + ((255 - value) * factor)).round(), 255)); Color tintColor(Color color, double factor) => Color.fromRGBO( tintValue(color.red, factor), tintValue(color.green, factor), tintValue(color.blue, factor), 1); @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( primaryColor: Palette.primary, colorScheme: ColorScheme.fromSwatch( primarySwatch: generateMaterialColor(Palette.primary), ).copyWith( secondary: generateMaterialColor(Palette.accent), ), ), darkTheme: ThemeData.from( colorScheme: const ColorScheme.dark( primary: Palette.accent, secondary: Palette.accent)), title: "GCG.MeinCantor", home: buildHomePage(), ); } } Future apiKeyEmpty() async { SharedPreferences prefs = await SharedPreferences.getInstance(); String? apiKey = prefs.getString("api_key"); return apiKey == null || apiKey.isEmpty; } Widget buildHomePage() { return FutureBuilder( future: apiKeyEmpty(), builder: (context, snapshot) { if (snapshot.data == true) { return Login(); } else if (snapshot.data == false) { return const Dashboard(); } else { return const Center(child: CircularProgressIndicator()); } }); } class Palette { static const Color primary = Color(0xFF1A1A37); static const Color accent = Color(0xFFFFBC3B); }