121 lines
4.1 KiB
Dart
121 lines
4.1 KiB
Dart
// ignore_for_file: prefer_const_constructors
|
|
|
|
import 'dart:ui';
|
|
|
|
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: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/wakelock.dart';
|
|
|
|
/// Provides access to the ObjectBox Store throughout the app.
|
|
late ObjectBox objectbox;
|
|
|
|
Future<void> main() async {
|
|
// This is required so ObjectBox can get the application directory
|
|
// to store the database in.
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await SharedPrefs().init();
|
|
|
|
objectbox = await ObjectBox.create();
|
|
|
|
/// Log
|
|
objectbox.addLog('LOG', 'MOBDR', 'Ouverture application ', 0);
|
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
|
|
.then((_) {
|
|
/// pour wakelock
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
Wakelock.enable();
|
|
|
|
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 {
|
|
// 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(),
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|