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

78 lines
2.3 KiB
Dart
Raw Normal View History

2019-04-23 16:11:19 +00:00
import 'package:comunic/helpers/account_helper.dart';
2019-04-24 09:24:05 +00:00
import 'package:comunic/helpers/database/database_helper.dart';
2019-11-01 12:48:40 +00:00
import 'package:comunic/helpers/preferences_helper.dart';
2021-03-14 17:15:38 +00:00
import 'package:comunic/helpers/serialization/user_list_serialization_helper.dart';
import 'package:comunic/helpers/version_helper.dart';
2021-04-24 06:57:20 +00:00
import 'package:comunic/models/config.dart';
2020-04-17 13:25:26 +00:00
import 'package:comunic/ui/widgets/init_widget.dart';
2021-03-14 16:44:29 +00:00
import 'package:comunic/utils/flutter_utils.dart';
2020-03-28 16:11:11 +00:00
import 'package:comunic/utils/intl_utils.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
2019-04-21 08:34:27 +00:00
import 'package:flutter/material.dart';
2021-12-28 14:33:27 +00:00
import 'package:flutter/services.dart';
2019-04-21 08:34:27 +00:00
/// Main file of the application
///
/// @author Pierre HUBERT
2019-11-01 12:48:40 +00:00
void subMain() async {
WidgetsFlutterBinding.ensureInitialized();
// Load package information
await VersionHelper.ensureLoaded();
2019-04-24 09:24:05 +00:00
// Connect to database
2021-03-14 17:15:38 +00:00
if (!isWeb) {
2021-03-14 16:44:29 +00:00
await DatabaseHelper.open();
2021-03-14 17:15:38 +00:00
if (await Connectivity().checkConnectivity() != ConnectivityResult.none)
await UsersListSerialisationHelper().removeAll();
2021-03-14 16:44:29 +00:00
}
2019-04-24 09:24:05 +00:00
2020-03-28 16:11:11 +00:00
// Get current system language
await initTranslations();
2020-05-09 11:50:18 +00:00
// Check if the user is currently signed in
await AccountHelper().signedIn();
2020-05-09 11:50:18 +00:00
2019-11-01 12:48:40 +00:00
runApp(ComunicApplication(
2020-05-12 17:00:35 +00:00
preferences: await PreferencesHelper.getInstance(),
2019-11-01 12:48:40 +00:00
));
2019-04-21 08:34:27 +00:00
}
class ComunicApplication extends StatefulWidget {
2020-05-12 17:00:35 +00:00
final PreferencesHelper preferences;
2020-05-09 11:50:18 +00:00
const ComunicApplication({
Key? key,
required this.preferences,
2022-03-10 19:36:55 +00:00
}) : super(key: key);
2019-11-01 12:48:40 +00: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 08:34:27 +00:00
@override
Widget build(BuildContext context) {
2020-05-13 16:26:21 +00:00
final prefs = widget.preferences.preferences;
2019-04-21 08:34:27 +00:00
return MaterialApp(
2019-04-21 09:44:07 +00:00
debugShowCheckedModeBanner: false,
home: InitializeWidget(),
2021-04-24 06:57:20 +00:00
theme: (prefs.enableDarkMode ? ThemeData.dark() : ThemeData.fallback())
.copyWith(
primaryColor: config().primaryColor,
2021-04-24 08:06:36 +00:00
primaryColorDark: config().primaryColorDark,
appBarTheme: AppBarTheme(
2021-12-28 14:23:08 +00:00
backgroundColor: config().primaryColor,
2021-12-28 14:33:27 +00:00
systemOverlayStyle: SystemUiOverlayStyle.light,
2021-04-24 08:06:36 +00:00
)),
2020-05-13 16:26:21 +00:00
showPerformanceOverlay: prefs.showPerformancesOverlay,
2019-04-21 08:34:27 +00:00
);
}
}