selfprivacy.org.app/lib/main.dart

106 lines
3.5 KiB
Dart
Raw Normal View History

2022-02-10 11:50:37 +02:00
import 'package:easy_localization/easy_localization.dart';
2020-11-29 22:07:46 +02:00
import 'package:flutter/material.dart';
2021-01-13 18:45:46 +02: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 19:35:57 +02: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';
import 'package:selfprivacy/ui/router/router.dart';
// import 'package:wakelock/wakelock.dart';
2022-01-25 19:00:47 +02:00
import 'package:timezone/data/latest.dart' as tz;
2021-01-19 14:05:40 +02:00
2022-06-05 22:36:32 +03:00
import 'package:selfprivacy/config/bloc_config.dart';
import 'package:selfprivacy/config/bloc_observer.dart';
import 'package:selfprivacy/config/get_it_config.dart';
import 'package:selfprivacy/config/localization.dart';
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart';
2020-11-29 22:07:46 +02:00
2021-01-06 19:35:57 +02:00
void main() async {
2021-08-29 12:50:24 +03:00
WidgetsFlutterBinding.ensureInitialized();
2021-01-06 19:35:57 +02:00
await HiveConfig.init();
// await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
2022-04-29 13:45:15 +03:00
// try {
// /// Wakelock support for Linux
// /// desktop is not yet implemented
// await Wakelock.enable();
// } on PlatformException catch (e) {
// print(e);
// }
2022-04-29 13:45:15 +03:00
2021-03-25 22:09:56 +02:00
await getItSetup();
2021-03-14 21:18:51 +02:00
await EasyLocalization.ensureInitialized();
2022-01-25 19:00:47 +02:00
tz.initializeTimeZones();
2020-12-01 14:26:29 +02:00
2022-06-05 22:36:32 +03:00
final ThemeData lightThemeData = await AppThemeFactory.create(
2022-05-03 13:45:10 +03:00
isDark: false,
fallbackColor: BrandColors.primary,
);
2022-06-05 22:36:32 +03:00
final ThemeData darkThemeData = await AppThemeFactory.create(
2022-05-03 13:45:10 +03:00
isDark: true,
fallbackColor: BrandColors.primary,
);
Bloc.observer = SimpleBlocObserver();
runApp(
Localization(
child: SelfprivacyApp(
lightThemeData: lightThemeData,
darkThemeData: darkThemeData,
),
),
2022-01-25 19:00:47 +02:00
);
2020-11-29 22:07:46 +02:00
}
class SelfprivacyApp extends StatelessWidget {
SelfprivacyApp({
2022-05-03 13:45:10 +03:00
required this.lightThemeData,
required this.darkThemeData,
super.key,
2022-06-05 22:36:32 +03:00
});
2022-05-03 13:45:10 +03:00
final ThemeData lightThemeData;
final ThemeData darkThemeData;
final _appRouter = RootRouter(getIt.get<NavigationService>().navigatorKey);
2020-11-29 22:07:46 +02:00
@override
2022-06-05 22:36:32 +03:00
Widget build(final BuildContext context) => Localization(
child: BlocAndProviderConfig(
child: BlocBuilder<AppSettingsCubit, AppSettingsState>(
builder: (
final BuildContext context,
final AppSettingsState appSettings,
) =>
MaterialApp.router(
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(),
scaffoldMessengerKey:
getIt.get<NavigationService>().scaffoldMessengerKey,
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
debugShowCheckedModeBanner: false,
title: 'SelfPrivacy',
theme: lightThemeData,
darkTheme: darkThemeData,
themeMode: appSettings.isAutoDarkModeOn
? ThemeMode.system
: appSettings.isDarkModeOn
? ThemeMode.dark
: ThemeMode.light,
builder: (final BuildContext context, final Widget? widget) {
Widget error = const Text('...rendering error...');
if (widget is Scaffold || widget is Navigator) {
error = Scaffold(body: Center(child: error));
}
ErrorWidget.builder =
(final FlutterErrorDetails errorDetails) => error;
return widget!;
},
),
2022-03-23 16:07:52 +02:00
),
),
);
2020-11-29 22:07:46 +02:00
}