This repository has been archived on 2023-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
meincantor-app/lib/main.dart
Denys Konovalov e86c1bad1d = 0.8.0-dev =
- code cleanup
- caching
- black-/whitelist
- sz/news fixes
- added settings options
...
2021-12-13 13:39:06 +01:00

98 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dashboard.dart';
import 'login.dart';
import 'dart:math';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('app_icon');
final IOSInitializationSettings initializationSettingsIOS =
IOSInitializationSettings();
final MacOSInitializationSettings initializationSettingsMacOS =
MacOSInitializationSettings();
final InitializationSettings initializationSettings = InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,
macOS: initializationSettingsMacOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
runApp(const App());
}
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
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<bool> 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);
}