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

80 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(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);
}