mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-27 05:18:50 +00:00
76 lines
1.8 KiB
Dart
76 lines
1.8 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:comunic/utils/ui_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();
|
|
|
|
runApp(ComunicApplication(
|
|
darkMode: (await PreferencesHelper.getInstance())
|
|
.getBool(PreferencesKeyList.ENABLE_DARK_THEME),
|
|
));
|
|
}
|
|
|
|
class ComunicApplication extends StatelessWidget {
|
|
final bool darkMode;
|
|
|
|
const ComunicApplication({Key key, @required this.darkMode})
|
|
: assert(darkMode != null),
|
|
super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: ComunicApplicationHome(),
|
|
theme: darkMode ? ThemeData.dark() : ThemeData.light(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ComunicApplicationHome extends StatefulWidget {
|
|
@override
|
|
State<StatefulWidget> createState() => _ComunicApplicationHomeState();
|
|
}
|
|
|
|
class _ComunicApplicationHomeState extends State<ComunicApplicationHome> {
|
|
bool _signedIn;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
AccountHelper().signedIn().then((v) {
|
|
setState(() {
|
|
_signedIn = v;
|
|
});
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (_signedIn == null) return buildLoadingPage();
|
|
|
|
if (_signedIn)
|
|
return InitializeWidget();
|
|
else
|
|
return LoginRoute();
|
|
}
|
|
}
|