2019-04-23 18:11:19 +02:00
|
|
|
import 'package:comunic/helpers/account_helper.dart';
|
2019-04-24 11:24:05 +02:00
|
|
|
import 'package:comunic/helpers/database/database_helper.dart';
|
2019-11-01 13:48:40 +01:00
|
|
|
import 'package:comunic/helpers/preferences_helper.dart';
|
2019-04-22 19:16:26 +02:00
|
|
|
import 'package:comunic/ui/routes/login_route.dart';
|
2020-04-17 15:25:26 +02:00
|
|
|
import 'package:comunic/ui/widgets/init_widget.dart';
|
2020-03-28 17:11:11 +01:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
2019-04-21 10:34:27 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Main file of the application
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2019-11-01 13:48:40 +01:00
|
|
|
void subMain() async {
|
2020-03-24 13:15:49 +01:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2019-04-24 11:24:05 +02:00
|
|
|
// Connect to database
|
2019-11-01 13:48:40 +01:00
|
|
|
await DatabaseHelper.open();
|
2020-04-17 11:53:47 +02:00
|
|
|
await DatabaseHelper.cleanUpDatabase();
|
2019-04-24 11:24:05 +02:00
|
|
|
|
2020-03-28 17:11:11 +01:00
|
|
|
// Get current system language
|
|
|
|
await initTranslations();
|
|
|
|
|
2020-05-09 13:50:18 +02:00
|
|
|
// Check if the user is currently signed in
|
|
|
|
final signedIn = await AccountHelper().signedIn();
|
|
|
|
|
2019-11-01 13:48:40 +01:00
|
|
|
runApp(ComunicApplication(
|
|
|
|
darkMode: (await PreferencesHelper.getInstance())
|
|
|
|
.getBool(PreferencesKeyList.ENABLE_DARK_THEME),
|
2020-05-09 13:50:18 +02:00
|
|
|
signedIn: signedIn,
|
2019-11-01 13:48:40 +01:00
|
|
|
));
|
2019-04-21 10:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ComunicApplication extends StatelessWidget {
|
2019-11-01 13:48:40 +01:00
|
|
|
final bool darkMode;
|
2020-05-09 13:50:18 +02:00
|
|
|
final bool signedIn;
|
|
|
|
|
|
|
|
const ComunicApplication({
|
|
|
|
Key key,
|
|
|
|
@required this.darkMode,
|
|
|
|
@required this.signedIn,
|
|
|
|
}) : assert(darkMode != null),
|
|
|
|
assert(signedIn != null),
|
2019-11-01 13:48:40 +01:00
|
|
|
super(key: key);
|
|
|
|
|
2019-04-21 10:34:27 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2019-04-21 11:44:07 +02:00
|
|
|
debugShowCheckedModeBanner: false,
|
2020-05-09 13:50:18 +02:00
|
|
|
home: signedIn ? InitializeWidget() : LoginRoute(),
|
2019-11-01 14:17:46 +01:00
|
|
|
theme: darkMode ? ThemeData.dark() : ThemeData.light(),
|
2019-04-21 10:34:27 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|