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

84 lines
2.3 KiB
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'Dashboard.dart';
import 'Login.dart';
import 'dart:math';
void main() => runApp(App());
class App extends StatelessWidget {
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.accent),
).copyWith(
secondary: generateMaterialColor(Palette.accent),
),
),
darkTheme: ThemeData.from(colorScheme: ColorScheme.dark(primary: Palette.accent)),
title: "GCG.MeinCantor",
home: buildHomePage(),
/*
routes: <String, WidgetBuilder>{
"/": (_) => Dashboard(),
"/login": (_) => Login()
},
*/
);
}
}
Future<bool> apiKeyEmpty() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String? api_key = await prefs.getString("api_key");
return api_key == null || api_key.isEmpty;
}
Widget buildHomePage() {
return FutureBuilder(
future: apiKeyEmpty(),
builder: (context, snapshot) {
if(snapshot.data == true) {
return Login();
} else if(snapshot.data == false) {
return Dashboard();
} else {
return Center(child: CircularProgressIndicator());
}
}
);
}
class Palette {
static const Color primary = Color(0xFF1A1A37);
static const Color accent = Color(0xFFFFBC3B);
}