2022-06-16 20:30:02 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-06-28 20:05:24 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2022-06-17 10:38:28 +00:00
|
|
|
import 'package:localization/localization.dart';
|
2022-06-16 20:30:02 +00:00
|
|
|
import 'package:slothmu/partials/main_scaffold.dart';
|
|
|
|
import 'pages/login.dart';
|
2022-07-01 22:41:37 +00:00
|
|
|
import 'business_logic/settings.dart' as settings;
|
2022-06-17 12:13:45 +00:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2022-07-02 17:32:44 +00:00
|
|
|
import 'themes/themes.dart' as themes;
|
2022-07-03 13:47:24 +00:00
|
|
|
import 'global.dart' as global;
|
2022-07-04 20:39:25 +00:00
|
|
|
import 'business_logic/auth/oauth.dart' as oauth;
|
2022-06-16 20:30:02 +00:00
|
|
|
|
2022-07-02 17:32:44 +00:00
|
|
|
String _initRoute = "/";
|
2022-07-02 22:03:10 +00:00
|
|
|
ThemeData theme = themes.getTheme(themes.available[0]);
|
2022-07-03 13:47:24 +00:00
|
|
|
Locale activeLocale = const Locale("en");
|
2022-07-01 22:41:37 +00:00
|
|
|
|
|
|
|
void main() async {
|
2022-07-03 13:47:24 +00:00
|
|
|
Intl.defaultLocale = "en";
|
|
|
|
await settings.saveLocale("en");
|
|
|
|
activeLocale = await settings.loadLocale();
|
2022-06-28 20:05:24 +00:00
|
|
|
|
2022-07-01 22:41:37 +00:00
|
|
|
// check if all information is available
|
|
|
|
if (await settings.loadAuthCode() == "") {
|
2022-07-04 20:39:25 +00:00
|
|
|
_initRoute = "/login";
|
|
|
|
} else {
|
|
|
|
await oauth.refreshToken();
|
2022-07-01 22:41:37 +00:00
|
|
|
}
|
2022-06-28 20:05:24 +00:00
|
|
|
runApp(const Slothmu());
|
|
|
|
}
|
2022-06-17 12:13:45 +00:00
|
|
|
|
|
|
|
class Slothmu extends StatefulWidget {
|
|
|
|
const Slothmu({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Slothmu> createState() => _SlothmuState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SlothmuState extends State<Slothmu> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
LocalJsonLocalization.delegate.directories = ['lib/i18n'];
|
|
|
|
return MaterialApp(
|
2022-07-02 22:03:10 +00:00
|
|
|
theme: theme,
|
2022-07-03 13:47:24 +00:00
|
|
|
locale: activeLocale,
|
|
|
|
supportedLocales: global.availableLocales,
|
2022-06-17 10:38:28 +00:00
|
|
|
localizationsDelegates: [
|
2022-06-17 12:13:45 +00:00
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
2022-06-17 10:38:28 +00:00
|
|
|
LocalJsonLocalization.delegate,
|
|
|
|
],
|
2022-07-02 17:32:44 +00:00
|
|
|
initialRoute: _initRoute,
|
2022-06-16 20:30:02 +00:00
|
|
|
routes: {
|
|
|
|
'/': (context) => const MainScaffold(),
|
|
|
|
'/login': (context) => const Login(),
|
|
|
|
},
|
2022-06-17 12:13:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|