2021-08-27 19:24:30 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2021-09-14 20:55:58 +02:00
|
|
|
import 'dashboard.dart';
|
|
|
|
import 'login.dart';
|
2021-08-27 19:24:30 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
void main() => runApp(const App());
|
2021-08-27 19:24:30 +02:00
|
|
|
|
|
|
|
class App extends StatelessWidget {
|
2021-09-14 20:55:58 +02:00
|
|
|
const App({Key? key}) : super(key: key);
|
|
|
|
|
2021-08-27 19:24:30 +02:00
|
|
|
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(
|
2021-09-14 20:55:58 +02:00
|
|
|
primarySwatch: generateMaterialColor(Palette.primary),
|
2021-08-27 19:24:30 +02:00
|
|
|
).copyWith(
|
|
|
|
secondary: generateMaterialColor(Palette.accent),
|
|
|
|
),
|
|
|
|
),
|
2021-09-14 20:55:58 +02:00
|
|
|
darkTheme: ThemeData.from(
|
2021-11-06 11:01:44 +01:00
|
|
|
colorScheme: const ColorScheme.dark(primary: Palette.accent, secondary: Palette.accent)),
|
2021-08-27 19:24:30 +02:00
|
|
|
title: "GCG.MeinCantor",
|
|
|
|
home: buildHomePage(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> apiKeyEmpty() async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
2021-09-14 20:55:58 +02:00
|
|
|
String? apiKey = prefs.getString("api_key");
|
|
|
|
return apiKey == null || apiKey.isEmpty;
|
2021-08-27 19:24:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildHomePage() {
|
|
|
|
return FutureBuilder(
|
2021-09-14 20:55:58 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
});
|
2021-08-27 19:24:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class Palette {
|
2021-09-14 20:55:58 +02:00
|
|
|
static const Color primary = Color(0xFF1A1A37);
|
|
|
|
static const Color accent = Color(0xFFFFBC3B);
|
|
|
|
}
|