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';
|
2021-03-14 18:15:38 +01:00
|
|
|
import 'package:comunic/helpers/serialization/user_list_serialization_helper.dart';
|
2021-02-20 08:58:03 +01:00
|
|
|
import 'package:comunic/helpers/version_helper.dart';
|
2021-04-24 08:57:20 +02:00
|
|
|
import 'package:comunic/models/config.dart';
|
2020-04-17 15:25:26 +02:00
|
|
|
import 'package:comunic/ui/widgets/init_widget.dart';
|
2021-03-14 17:44:29 +01:00
|
|
|
import 'package:comunic/utils/flutter_utils.dart';
|
2020-03-28 17:11:11 +01:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
2022-03-10 18:37:59 +01:00
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
2019-04-21 10:34:27 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-12-28 15:33:27 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2019-04-21 10:34:27 +02:00
|
|
|
|
|
|
|
/// 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();
|
|
|
|
|
2021-02-20 08:58:03 +01:00
|
|
|
// Load package information
|
|
|
|
await VersionHelper.ensureLoaded();
|
|
|
|
|
2019-04-24 11:24:05 +02:00
|
|
|
// Connect to database
|
2021-03-14 18:15:38 +01:00
|
|
|
if (!isWeb) {
|
2021-03-14 17:44:29 +01:00
|
|
|
await DatabaseHelper.open();
|
2021-03-14 18:15:38 +01:00
|
|
|
|
|
|
|
if (await Connectivity().checkConnectivity() != ConnectivityResult.none)
|
|
|
|
await UsersListSerialisationHelper().removeAll();
|
2021-03-14 17:44:29 +01:00
|
|
|
}
|
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
|
2020-05-12 19:04:53 +02:00
|
|
|
await AccountHelper().signedIn();
|
2020-05-09 13:50:18 +02:00
|
|
|
|
2019-11-01 13:48:40 +01:00
|
|
|
runApp(ComunicApplication(
|
2020-05-12 19:00:35 +02:00
|
|
|
preferences: await PreferencesHelper.getInstance(),
|
2019-11-01 13:48:40 +01:00
|
|
|
));
|
2019-04-21 10:34:27 +02:00
|
|
|
}
|
|
|
|
|
2020-05-12 19:18:42 +02:00
|
|
|
class ComunicApplication extends StatefulWidget {
|
2020-05-12 19:00:35 +02:00
|
|
|
final PreferencesHelper preferences;
|
2020-05-09 13:50:18 +02:00
|
|
|
|
|
|
|
const ComunicApplication({
|
2022-03-10 19:39:57 +01:00
|
|
|
Key? key,
|
|
|
|
required this.preferences,
|
2022-03-10 20:36:55 +01:00
|
|
|
}) : super(key: key);
|
2019-11-01 13:48:40 +01:00
|
|
|
|
2020-05-12 19:18:42 +02:00
|
|
|
@override
|
|
|
|
ComunicApplicationState createState() => ComunicApplicationState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class ComunicApplicationState extends State<ComunicApplication> {
|
|
|
|
/// Use this method to force the application to rebuild
|
|
|
|
void refresh() => setState(() {});
|
|
|
|
|
2019-04-21 10:34:27 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-05-13 18:26:21 +02:00
|
|
|
final prefs = widget.preferences.preferences;
|
|
|
|
|
2019-04-21 10:34:27 +02:00
|
|
|
return MaterialApp(
|
2019-04-21 11:44:07 +02:00
|
|
|
debugShowCheckedModeBanner: false,
|
2021-02-19 17:32:38 +01:00
|
|
|
home: InitializeWidget(),
|
2021-04-24 08:57:20 +02:00
|
|
|
theme: (prefs.enableDarkMode ? ThemeData.dark() : ThemeData.fallback())
|
|
|
|
.copyWith(
|
|
|
|
primaryColor: config().primaryColor,
|
2021-04-24 10:06:36 +02:00
|
|
|
primaryColorDark: config().primaryColorDark,
|
|
|
|
appBarTheme: AppBarTheme(
|
2021-12-28 15:23:08 +01:00
|
|
|
backgroundColor: config().primaryColor,
|
2021-12-28 15:33:27 +01:00
|
|
|
systemOverlayStyle: SystemUiOverlayStyle.light,
|
2021-04-24 10:06:36 +02:00
|
|
|
)),
|
2020-05-13 18:26:21 +02:00
|
|
|
showPerformanceOverlay: prefs.showPerformancesOverlay,
|
2019-04-21 10:34:27 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|