196 lines
6.7 KiB
Dart
196 lines
6.7 KiB
Dart
import 'dart:ui';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
import 'objectbox.dart';
|
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
|
import 'package:event_bus_plus/event_bus_plus.dart';
|
|
|
|
import 'package:mobdr/service/logger_util.dart';
|
|
import 'package:mobdr/config/constant.dart';
|
|
import 'package:mobdr/cubit/language/language_cubit.dart';
|
|
import 'package:mobdr/cubit/language/app_localizations.dart';
|
|
import 'package:mobdr/cubit/language/initial_language.dart';
|
|
import 'package:mobdr/service/shared_prefs.dart';
|
|
import 'package:mobdr/ui/splash_screen.dart';
|
|
import 'package:mobdr/service/device_info.dart';
|
|
import 'package:mobdr/service/package_info.dart';
|
|
import 'package:mobdr/service/directories.dart';
|
|
import 'package:mobdr/service/plausible.dart';
|
|
|
|
/// Provides access to the ObjectBox Store throughout the app.
|
|
late ObjectBox objectbox;
|
|
|
|
final EventBus eventBus = EventBus();
|
|
|
|
String getCurrentTimeZone(DateTime dateTime) {
|
|
Duration offset = dateTime.timeZoneOffset;
|
|
int offsetHours = offset.inHours;
|
|
int offsetMinutes = offset.inMinutes.remainder(60);
|
|
|
|
String offsetSign = offset.isNegative ? '-' : '+';
|
|
String timeZone =
|
|
'$offsetSign${offsetHours.abs().toString().padLeft(2, '0')}:${offsetMinutes.abs().toString().padLeft(2, '0')}';
|
|
|
|
return timeZone;
|
|
}
|
|
|
|
Future<void> main() async {
|
|
// This is required so ObjectBox can get the application directory
|
|
// to store the database in.
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// registration of the observer
|
|
WidgetsBinding.instance.addObserver(MyApp());
|
|
|
|
LoggerUtil.logNStackInfo('Application MobDR started');
|
|
|
|
// create database object
|
|
objectbox = await ObjectBox.create();
|
|
|
|
// initialize shared preferences
|
|
await SharedPrefs().init();
|
|
|
|
// get/set device informations
|
|
await device_info_plus().initPlatformState();
|
|
|
|
// get/set device informations
|
|
await package_info_plus().initPackageInfo();
|
|
|
|
// set device screenWidth/height
|
|
SharedPrefs().screenWidth =
|
|
PlatformDispatcher.instance.views.first.physicalSize.width;
|
|
SharedPrefs().screenHeight =
|
|
PlatformDispatcher.instance.views.first.physicalSize.height;
|
|
|
|
// initialize directories
|
|
await directories().initDirectories();
|
|
|
|
/// initialize tracker plausible analytics
|
|
await PlausibleUtil.initializePlausible();
|
|
|
|
// initialize time zone current device
|
|
SharedPrefs().timeZone = getCurrentTimeZone(DateTime.now());
|
|
|
|
// url MP4
|
|
SharedPrefs().urlMP4 =
|
|
'https://mp4.ikksgroup.com/MobilePortal4/index.html#ajax/dashboard.html';
|
|
|
|
// track MobBR
|
|
LoggerUtil.dblog(
|
|
'LOG', 'MOBDR', 'Démarrage MobDR ' + SharedPrefs().appVersion, 0);
|
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
|
|
.then((_) {
|
|
/// pour wakelock
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
WakelockPlus.enable();
|
|
|
|
eventBus.on().listen((event) {
|
|
if (!(event is EmptyEvent)) {
|
|
LoggerUtil.logNStackInfo('${DateTime.now()} Event: $event');
|
|
}
|
|
});
|
|
|
|
runApp(MyApp());
|
|
});
|
|
}
|
|
|
|
class MyCustomScrollBehavior extends MaterialScrollBehavior {
|
|
// Override behavior methods and getters like dragDevices
|
|
@override
|
|
Set<PointerDeviceKind> get dragDevices => {
|
|
PointerDeviceKind.touch,
|
|
PointerDeviceKind.mouse,
|
|
// etc.
|
|
};
|
|
}
|
|
|
|
class MyApp extends StatelessWidget with WidgetsBindingObserver {
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
|
if (state == AppLifecycleState.paused) {
|
|
LoggerUtil.logNStackInfo("The application is paused");
|
|
} else if (state == AppLifecycleState.resumed) {
|
|
LoggerUtil.logNStackInfo("The application is resumed");
|
|
|
|
// check if plausible is up and running
|
|
await PlausibleUtil.checkPlausibleUp();
|
|
} else if (state == AppLifecycleState.inactive) {
|
|
LoggerUtil.logNStackInfo("The application is inactive");
|
|
} else if (state == AppLifecycleState.detached) {
|
|
LoggerUtil.logNStackInfo("The application is detached");
|
|
eventBus.dispose();
|
|
}
|
|
|
|
if (state == AppLifecycleState.resumed) {
|
|
} else if (state == AppLifecycleState.inactive) {
|
|
LoggerUtil.logNStackInfo("The application runs in the background");
|
|
}
|
|
}
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Initialize all bloc provider used on this entire application here
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
// this bloc used for feature - change language
|
|
BlocProvider<LanguageCubit>(
|
|
create: (BuildContext context) => LanguageCubit(),
|
|
),
|
|
],
|
|
// if you want to change default language, go to lib/ui/feature/multi_language/initial_language.dart and change en US to your default language
|
|
child: InitialLanguage(
|
|
child: BlocBuilder<LanguageCubit, LanguageState>(
|
|
builder: (context, state) {
|
|
return MaterialApp(
|
|
scrollBehavior: MyCustomScrollBehavior(),
|
|
title: APP_NAME,
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
pageTransitionsTheme: PageTransitionsTheme(builders: {
|
|
/*
|
|
Below is the example to change MaterialPageRoute default transition in iOS and Android :
|
|
FadeUpwardsPageTransitionsBuilder() <= Default MaterialPageRoute Transition
|
|
OpenUpwardsPageTransitionsBuilder()
|
|
ZoomPageTransitionsBuilder()
|
|
CupertinoPageTransitionsBuilder()
|
|
*/
|
|
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
|
|
TargetPlatform.android: ZoomPageTransitionsBuilder(),
|
|
}),
|
|
),
|
|
// below is used for language feature
|
|
supportedLocales: [
|
|
Locale('fr', 'FR'),
|
|
Locale('en', 'US'),
|
|
Locale('id', 'ID'),
|
|
Locale('ar', 'DZ'),
|
|
Locale('zh', 'HK'),
|
|
Locale('hi', 'IN'),
|
|
Locale('th', 'TH'),
|
|
Locale('tk', 'TK'),
|
|
],
|
|
// These delegates make sure that the localization data for the proper language is loaded
|
|
localizationsDelegates: [
|
|
AppLocalizationsDelegate(),
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate
|
|
],
|
|
// Returns a locale which will be used by the app
|
|
locale: (state is ChangeLanguageSuccess)
|
|
? state.locale
|
|
: Locale('fr', 'FR'),
|
|
home: SplashScreenPage(),
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|