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; ThemeData theme = themes.getTheme(themes.available[1]); Locale activeLocale = const Locale("en_US"); void main() async { 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 createState() => _LorisState(); } class _LorisState extends State { 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" : "/", routes: { '/': (context) => const MainScaffold(), '/login': (context) => const Login(), }, ); } }