2022-02-10 12:50:37 +03:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2020-11-29 21:07:46 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2021-01-13 17:45:46 +01:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2022-05-03 13:45:10 +03:00
|
|
|
import 'package:selfprivacy/config/brand_colors.dart';
|
2021-01-06 18:35:57 +01:00
|
|
|
import 'package:selfprivacy/config/hive_config.dart';
|
2022-05-03 13:45:10 +03:00
|
|
|
import 'package:selfprivacy/theming/factory/app_theme_factory.dart';
|
2022-05-10 23:42:33 +03:00
|
|
|
import 'package:selfprivacy/ui/pages/setup/initializing.dart';
|
2020-11-29 21:07:46 +01:00
|
|
|
import 'package:selfprivacy/ui/pages/onboarding/onboarding.dart';
|
2020-12-03 17:52:53 +01:00
|
|
|
import 'package:selfprivacy/ui/pages/rootRoute.dart';
|
2021-01-19 13:05:40 +01:00
|
|
|
import 'package:wakelock/wakelock.dart';
|
2022-01-25 18:00:47 +01:00
|
|
|
import 'package:timezone/data/latest.dart' as tz;
|
2021-01-19 13:05:40 +01:00
|
|
|
|
2020-12-01 20:08:19 +01:00
|
|
|
import 'config/bloc_config.dart';
|
2021-01-13 17:45:46 +01:00
|
|
|
import 'config/bloc_observer.dart';
|
2021-01-14 22:48:05 +01:00
|
|
|
import 'config/get_it_config.dart';
|
2020-12-01 13:26:29 +01:00
|
|
|
import 'config/localization.dart';
|
2020-12-08 20:26:51 +01:00
|
|
|
import 'logic/cubit/app_settings/app_settings_cubit.dart';
|
2020-11-29 21:07:46 +01:00
|
|
|
|
2021-01-06 18:35:57 +01:00
|
|
|
void main() async {
|
2021-08-29 11:50:24 +02:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2021-01-06 18:35:57 +01:00
|
|
|
await HiveConfig.init();
|
2021-09-29 20:28:47 +02:00
|
|
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2022-04-29 13:45:15 +03:00
|
|
|
|
|
|
|
try {
|
2022-05-04 22:32:24 +03:00
|
|
|
/// Wakelock support for Linux
|
|
|
|
/// desktop is not yet implemented
|
2022-04-29 13:45:15 +03:00
|
|
|
await Wakelock.enable();
|
|
|
|
} on PlatformException catch (e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
|
2021-03-25 21:09:56 +01:00
|
|
|
await getItSetup();
|
2021-03-14 20:18:51 +01:00
|
|
|
await EasyLocalization.ensureInitialized();
|
2022-01-25 18:00:47 +01:00
|
|
|
tz.initializeTimeZones();
|
2020-12-01 13:26:29 +01:00
|
|
|
|
2022-05-03 13:45:10 +03:00
|
|
|
final lightThemeData = await AppThemeFactory.create(
|
|
|
|
isDark: false,
|
|
|
|
fallbackColor: BrandColors.primary,
|
|
|
|
);
|
|
|
|
final darkThemeData = await AppThemeFactory.create(
|
|
|
|
isDark: true,
|
|
|
|
fallbackColor: BrandColors.primary,
|
|
|
|
);
|
|
|
|
|
2022-01-25 18:00:47 +01:00
|
|
|
BlocOverrides.runZoned(
|
2022-05-17 01:41:00 +03:00
|
|
|
() => runApp(Localization(
|
|
|
|
child: MyApp(
|
2022-05-03 13:45:10 +03:00
|
|
|
lightThemeData: lightThemeData,
|
|
|
|
darkThemeData: darkThemeData,
|
|
|
|
))),
|
2022-01-25 18:00:47 +01:00
|
|
|
blocObserver: SimpleBlocObserver(),
|
|
|
|
);
|
2020-11-29 21:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2022-05-03 13:45:10 +03:00
|
|
|
const MyApp({
|
|
|
|
required this.lightThemeData,
|
|
|
|
required this.darkThemeData,
|
|
|
|
});
|
|
|
|
|
|
|
|
final ThemeData lightThemeData;
|
|
|
|
final ThemeData darkThemeData;
|
|
|
|
|
2020-11-29 21:07:46 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-07-29 07:24:42 +02:00
|
|
|
return Localization(
|
2022-03-23 17:07:52 +03:00
|
|
|
child: AnnotatedRegion<SystemUiOverlayStyle>(
|
|
|
|
value: SystemUiOverlayStyle.light, // Manually changing appbar color
|
|
|
|
child: BlocAndProviderConfig(
|
|
|
|
child: BlocBuilder<AppSettingsCubit, AppSettingsState>(
|
|
|
|
builder: (context, appSettings) {
|
|
|
|
return MaterialApp(
|
|
|
|
scaffoldMessengerKey:
|
|
|
|
getIt.get<NavigationService>().scaffoldMessengerKey,
|
|
|
|
navigatorKey: getIt.get<NavigationService>().navigatorKey,
|
|
|
|
localizationsDelegates: context.localizationDelegates,
|
|
|
|
supportedLocales: context.supportedLocales,
|
|
|
|
locale: context.locale,
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
title: 'SelfPrivacy',
|
2022-05-03 13:45:10 +03:00
|
|
|
theme: lightThemeData,
|
|
|
|
darkTheme: darkThemeData,
|
2022-05-17 01:41:00 +03:00
|
|
|
themeMode:
|
|
|
|
appSettings.isDarkModeOn ? ThemeMode.dark : ThemeMode.light,
|
2022-05-17 23:08:28 +03:00
|
|
|
home: appSettings.isOnboardingShowing
|
2022-03-23 17:07:52 +03:00
|
|
|
? 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 21:07:46 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|