Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/bloc/notification/notification_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -261,12 +262,14 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
ComputeNotificationEvent event,
Emitter<NotificationState> 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(
Expand Down Expand Up @@ -313,7 +316,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
storageService.readBool(Const.notificationFavoriteSlotsEnabledKey) ??
Const.notificationFavoriteSlotsEnabledDefaultValue;

final enabled = await notificationService.areNotificationsEnabled();
//final enabled = await notificationService.areNotificationsEnabled();

emit(
state.copyWith(
Expand All @@ -327,7 +330,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
openingNotificationEnabled: openingNotificationEnabled,
closingNotificationEnabled: closingNotificationEnabled,
timeSlotsEnabledForNotifications: enabledForNotifications,
notificationEnabled: enabled,
notificationEnabled: false,
),
);
}
Expand Down
97 changes: 53 additions & 44 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:developer' as developer;

import 'package:chabo_app/chabo.dart';
Expand All @@ -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);
});
}
33 changes: 1 addition & 32 deletions lib/screens/notification_screen/notification_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,38 +139,7 @@ class _NotificationScreenState extends CustomWidgetState<NotificationScreen> {
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<NotificationBloc>(context)
.add(
DurationNotificationValueEvent(
duration: Duration(
hours: value.hour,
minutes: value.minute,
),
),
),
},
},
);
},
onTap: null,
onChanged: (bool value) =>
BlocProvider.of<NotificationBloc>(context).add(
DurationNotificationStateEvent(
Expand Down
5 changes: 4 additions & 1 deletion lib/widgets/ad_banner_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -47,7 +48,9 @@ class _AdBannerWidgetState extends State<AdBannerWidget> {

@override
void initState() {
_createBannerAd();
if (!kIsWeb) {
_createBannerAd();
}
super.initState();
}

Expand Down