1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/main.dart

54 lines
1.4 KiB
Dart

import 'package:comunic/helpers/account_helper.dart';
import 'package:comunic/helpers/database/database_helper.dart';
import 'package:comunic/helpers/preferences_helper.dart';
import 'package:comunic/ui/routes/login_route.dart';
import 'package:comunic/ui/widgets/init_widget.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Main file of the application
///
/// @author Pierre HUBERT
void subMain() async {
WidgetsFlutterBinding.ensureInitialized();
// Connect to database
await DatabaseHelper.open();
await DatabaseHelper.cleanUpDatabase();
// Get current system language
await initTranslations();
// Check if the user is currently signed in
final signedIn = await AccountHelper().signedIn();
runApp(ComunicApplication(
darkMode: (await PreferencesHelper.getInstance())
.getBool(PreferencesKeyList.ENABLE_DARK_THEME),
signedIn: signedIn,
));
}
class ComunicApplication extends StatelessWidget {
final bool darkMode;
final bool signedIn;
const ComunicApplication({
Key key,
@required this.darkMode,
@required this.signedIn,
}) : assert(darkMode != null),
assert(signedIn != null),
super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: signedIn ? InitializeWidget() : LoginRoute(),
theme: darkMode ? ThemeData.dark() : ThemeData.light(),
);
}
}