diff --git a/lib/bloc/notification/notification_bloc.dart b/lib/bloc/notification/notification_bloc.dart index 3828feac..c8e6688f 100644 --- a/lib/bloc/notification/notification_bloc.dart +++ b/lib/bloc/notification/notification_bloc.dart @@ -8,6 +8,7 @@ import 'package:chabo_app/models/abstract_forecast.dart'; import 'package:chabo_app/models/enums/day.dart'; import 'package:chabo_app/service/notification_service.dart'; import 'package:chabo_app/service/storage_service.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -261,12 +262,14 @@ class NotificationBloc extends Bloc { ComputeNotificationEvent event, Emitter emit, ) async { - await notificationService.computeNotifications( - event.forecasts, - state, - event.timeSlotsState, - event.context, - ); + if (!kIsWeb) { + await notificationService.computeNotifications( + event.forecasts, + state, + event.timeSlotsState, + event.context, + ); + } } void _onAppEvent( @@ -313,7 +316,7 @@ class NotificationBloc extends Bloc { storageService.readBool(Const.notificationFavoriteSlotsEnabledKey) ?? Const.notificationFavoriteSlotsEnabledDefaultValue; - final enabled = await notificationService.areNotificationsEnabled(); + //final enabled = await notificationService.areNotificationsEnabled(); emit( state.copyWith( @@ -327,7 +330,7 @@ class NotificationBloc extends Bloc { openingNotificationEnabled: openingNotificationEnabled, closingNotificationEnabled: closingNotificationEnabled, timeSlotsEnabledForNotifications: enabledForNotifications, - notificationEnabled: enabled, + notificationEnabled: false, ), ); } diff --git a/lib/main.dart b/lib/main.dart index ce364e92..2ce7fc50 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:developer' as developer; import 'package:chabo_app/chabo.dart'; @@ -14,58 +15,66 @@ import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; void main() async { - WidgetsFlutterBinding.ensureInitialized(); + await runZonedGuarded(() async { + WidgetsFlutterBinding.ensureInitialized(); - final StorageService storageService = StorageService( - sharedPreferences: await SharedPreferences.getInstance(), - ); - final ConsentFormService consentFormService = - ConsentFormService(consentRequestParameters: ConsentRequestParameters()); - final NotificationService notificationService = - await NotificationService.create( - storageService: storageService, - ); + final StorageService storageService = StorageService( + sharedPreferences: await SharedPreferences.getInstance(), + ); + final ConsentFormService consentFormService = ConsentFormService( + consentRequestParameters: ConsentRequestParameters()); + final NotificationService notificationService = + await NotificationService.create( + storageService: storageService, + ); - /// Initialize the Google Ads SDK - MobileAds.instance.initialize(); + /// Initialize the Google Ads SDK + if (!kIsWeb) { + MobileAds.instance.initialize(); + } - /// Show consent dialog using the User Messaging Platform (UPM) - consentFormService.showConsentForm(); + /// Show consent dialog using the User Messaging Platform (UPM) + if (!kIsWeb) { + consentFormService.showConsentForm(); + } - LicenseRegistry.addLicense(() async* { - final license = await rootBundle.loadString(Const.oflLicensePath); - yield LicenseEntryWithLineBreaks([Const.oflLicenseEntryName], license); - }); + LicenseRegistry.addLicense(() async* { + final license = await rootBundle.loadString(Const.oflLicensePath); + yield LicenseEntryWithLineBreaks([Const.oflLicenseEntryName], license); + }); - /// Fetch app release to inject them into Sentry - final appRelease = await PackageInfo.fromPlatform(); - final formattedRelease = - '${appRelease.packageName}@${appRelease.version}+${appRelease.buildNumber}' - .toLowerCase(); + /// Fetch app release to inject them into Sentry + final appRelease = await PackageInfo.fromPlatform(); + final formattedRelease = + '${appRelease.packageName}@${appRelease.version}+${appRelease.buildNumber}' + .toLowerCase(); - /// Fetch running env - const env = - String.fromEnvironment(Const.envKey, defaultValue: Const.defaultEnv); + /// Fetch running env + const env = + String.fromEnvironment(Const.envKey, defaultValue: Const.defaultEnv); - developer.log( - '##### HI ! Starting $formattedRelease in $env mode #####', - name: 'chabo.main', - ); + developer.log( + '##### HI ! Starting $formattedRelease in $env mode #####', + name: 'chabo.main', + ); - await SentryFlutter.init( - (options) { - options.dsn = const String.fromEnvironment(Const.sentryDSNEnvKey); - options.tracesSampleRate = 0.5; - options.release = formattedRelease; - options.environment = env; - }, - appRunner: () => runApp( - SentryUserInteractionWidget( - child: Chabo( - storageService: storageService, - notificationService: notificationService, + await SentryFlutter.init( + (options) { + options.dsn = const String.fromEnvironment(Const.sentryDSNEnvKey); + options.tracesSampleRate = 0.5; + options.release = formattedRelease; + options.environment = env; + }, + appRunner: () => runApp( + SentryUserInteractionWidget( + child: Chabo( + storageService: storageService, + notificationService: notificationService, + ), ), ), - ), - ); + ); + }, (exception, stackTrace) async { + await Sentry.captureException(exception, stackTrace: stackTrace); + }); } diff --git a/lib/screens/notification_screen/notification_screen.dart b/lib/screens/notification_screen/notification_screen.dart index ec37d0ef..55f69b44 100644 --- a/lib/screens/notification_screen/notification_screen.dart +++ b/lib/screens/notification_screen/notification_screen.dart @@ -139,38 +139,7 @@ class _NotificationScreenState extends CustomWidgetState { height: 20, ), _CustomListTileWidget( - onTap: () { - showTimePicker( - initialEntryMode: TimePickerEntryMode.dial, - context: context, - initialTime: notificationState - .durationNotificationValue - .durationToTimeOfDay(), - builder: (BuildContext context, Widget? child) { - return MediaQuery( - data: MediaQuery.of(context).copyWith( - alwaysUse24HourFormat: true, - ), - child: child!, - ); - }, - ).then( - (value) => { - if (value != null) - { - BlocProvider.of(context) - .add( - DurationNotificationValueEvent( - duration: Duration( - hours: value.hour, - minutes: value.minute, - ), - ), - ), - }, - }, - ); - }, + onTap: null, onChanged: (bool value) => BlocProvider.of(context).add( DurationNotificationStateEvent( diff --git a/lib/widgets/ad_banner_widget.dart b/lib/widgets/ad_banner_widget.dart index c7a92066..2b8a53cf 100644 --- a/lib/widgets/ad_banner_widget.dart +++ b/lib/widgets/ad_banner_widget.dart @@ -3,6 +3,7 @@ import 'dart:developer' as developer; import 'package:chabo_app/custom_properties.dart'; import 'package:chabo_app/helpers/ad_helper.dart'; import 'package:chabo_app/helpers/device_helper.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; @@ -47,7 +48,9 @@ class _AdBannerWidgetState extends State { @override void initState() { - _createBannerAd(); + if (!kIsWeb) { + _createBannerAd(); + } super.initState(); }