selfprivacy.org.app/lib/main.dart

68 lines
2.5 KiB
Dart
Raw Normal View History

2020-11-29 20:07:46 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2021-01-13 16:45:46 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
2021-01-06 17:35:57 +00:00
import 'package:selfprivacy/config/hive_config.dart';
import 'package:selfprivacy/ui/pages/initializing/initializing.dart';
2020-11-29 20:07:46 +00:00
import 'package:selfprivacy/ui/pages/onboarding/onboarding.dart';
2020-12-01 12:26:29 +00:00
import 'package:easy_localization/easy_localization.dart';
2020-12-03 16:52:53 +00:00
import 'package:selfprivacy/ui/pages/rootRoute.dart';
2021-01-19 12:05:40 +00:00
import 'package:wakelock/wakelock.dart';
2020-12-01 19:08:19 +00:00
import 'config/bloc_config.dart';
2021-01-13 16:45:46 +00:00
import 'config/bloc_observer.dart';
2020-11-29 20:07:46 +00:00
import 'config/brand_theme.dart';
2021-01-14 21:48:05 +00:00
import 'config/get_it_config.dart';
2020-12-01 12:26:29 +00:00
import 'config/localization.dart';
2020-12-08 19:26:51 +00:00
import 'logic/cubit/app_settings/app_settings_cubit.dart';
2020-11-29 20:07:46 +00:00
2021-01-06 17:35:57 +00:00
void main() async {
2021-08-29 09:50:24 +00:00
WidgetsFlutterBinding.ensureInitialized();
2021-01-06 17:35:57 +00:00
await HiveConfig.init();
2021-09-29 18:28:47 +00:00
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
2021-02-15 18:58:29 +00:00
Bloc.observer = SimpleBlocObserver();
2021-01-19 12:05:40 +00:00
Wakelock.enable();
2021-03-25 20:09:56 +00:00
await getItSetup();
2021-03-14 19:18:51 +00:00
await EasyLocalization.ensureInitialized();
2020-12-01 12:26:29 +00:00
2021-07-29 05:24:42 +00:00
runApp(MyApp());
2020-11-29 20:07:46 +00:00
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
2021-07-29 05:24:42 +00:00
return Localization(
child: BlocAndProviderConfig(
child: Builder(builder: (context) {
var appSettings = context.watch<AppSettingsCubit>().state;
2021-01-06 17:35:57 +00:00
2021-07-29 05:24:42 +00:00
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light, // Manually changnig appbar color
child: MaterialApp(
2021-08-29 09:50:24 +00:00
scaffoldMessengerKey:
getIt.get<NavigationService>().scaffoldMessengerKey,
2021-07-29 05:24:42 +00:00
navigatorKey: getIt.get<NavigationService>().navigatorKey,
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: false,
title: 'SelfPrivacy',
theme: appSettings.isDarkModeOn ? darkTheme : ligtTheme,
home: appSettings.isOnbordingShowing
? OnboardingPage(nextPage: InitializingPage())
: RootPage(),
builder: (BuildContext context, Widget? widget) {
Widget error = Text('...rendering error...');
if (widget is Scaffold || widget is Navigator)
error = Scaffold(body: Center(child: error));
ErrorWidget.builder =
(FlutterErrorDetails errorDetails) => error;
return widget!;
},
),
);
}),
2020-11-29 20:07:46 +00:00
),
);
}
}