89 lines
2.4 KiB
Dart
89 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:localization/localization.dart';
|
|
import 'package:loris/pages/settings/app.dart';
|
|
import 'package:loris/partials/main_scaffold.dart';
|
|
import 'pages/login.dart';
|
|
import 'business_logic/settings.dart' as settings;
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'themes/themes.dart' as themes;
|
|
import 'global.dart' as global;
|
|
import 'package:url_strategy/url_strategy.dart';
|
|
|
|
ThemeData theme = themes.getTheme(themes.available[1]);
|
|
Locale activeLocale = const Locale("en_US");
|
|
|
|
void main() async {
|
|
setPathUrlStrategy();
|
|
Intl.defaultLocale = "en_US";
|
|
global.settings = await settings.Settings.create();
|
|
activeLocale = global.settings!.locale;
|
|
|
|
// check if all information is available
|
|
if (global.settings!.identities.isNotEmpty) {
|
|
// await oauth.refreshToken();
|
|
}
|
|
runApp(const Loris());
|
|
}
|
|
|
|
class Loris extends StatefulWidget {
|
|
const Loris({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<Loris> createState() => _LorisState();
|
|
}
|
|
|
|
class _LorisState extends State<Loris> {
|
|
var theme = global.settings!.theme;
|
|
|
|
@override
|
|
void initState() {
|
|
themeStream.stream.listen((event) {
|
|
setState(() {
|
|
theme = event;
|
|
});
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
LocalJsonLocalization.delegate.directories = ['lib/i18n'];
|
|
return MaterialApp(
|
|
theme: themes.getTheme(theme),
|
|
locale: activeLocale,
|
|
supportedLocales: global.availableLocales,
|
|
localizationsDelegates: [
|
|
GlobalCupertinoLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
LocalJsonLocalization.delegate,
|
|
],
|
|
initialRoute: global.settings!.identities.isEmpty ? "/login" : "/",
|
|
onGenerateRoute: (s) => RouterGenerator.generateRoute(s),
|
|
);
|
|
}
|
|
}
|
|
|
|
class RouterGenerator {
|
|
static Route<dynamic> generateRoute(RouteSettings s) {
|
|
var routingData = s.name;
|
|
switch (routingData) {
|
|
case "/login":
|
|
return MaterialPageRoute(
|
|
builder: (context) {
|
|
return const Login();
|
|
},
|
|
settings: s,
|
|
);
|
|
default:
|
|
return MaterialPageRoute(
|
|
builder: (context) {
|
|
return const MainScaffold();
|
|
},
|
|
settings: s,
|
|
);
|
|
}
|
|
}
|
|
}
|