Skip to content

Commit

Permalink
[Infrastructure] Make sure we initialize the location on the notifica…
Browse files Browse the repository at this point in the history
…tion_service.dart
  • Loading branch information
Wolfteam committed Jun 5, 2021
1 parent c367762 commit caa1ccb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/infrastructure/notification_service.dart
Expand Up @@ -5,14 +5,17 @@ import 'package:flutter_native_timezone/flutter_native_timezone.dart';
import 'package:genshindb/domain/enums/enums.dart';
import 'package:genshindb/domain/services/logging_service.dart';
import 'package:genshindb/domain/services/notification_service.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;

const _channelId = 'genshindb_channel';
const _channelName = 'Notifications';
const _channelDescription = 'Notifications from the app';
const _largeIcon = 'genshin_db';

//Here we use this one in particular cause this tz uses UTC and does not use any kind of dst.
const _fallbackTimeZone = 'Africa/Accra';

class NotificationServiceImpl implements NotificationService {
final LoggingService _loggingService;

Expand All @@ -29,7 +32,11 @@ class NotificationServiceImpl implements NotificationService {
_location = tz.getLocation(currentTimeZone) ?? tz.local;
tz.setLocalLocation(_location);
} catch (e, s) {
_loggingService.error(runtimeType, 'init: Unknown error occurred', e, s);
//https://github.com/srawlins/timezone/issues/92
_loggingService.error(runtimeType, 'init: Failed to get timezone or device is GMT or UTC, assigning the generic one...', e, s);
_location = tz.getLocation(_fallbackTimeZone);
assert(_location != null);
tz.setLocalLocation(_location);
}
}

Expand Down Expand Up @@ -85,6 +92,7 @@ class NotificationServiceImpl implements NotificationService {
await showNotification(id, type, title, body, payload: payload);
return;
}
assert(_location != null);
final newId = _generateUniqueId(id, type);
final specifics = _getPlatformChannelSpecifics(type, body);
final scheduledDate = tz.TZDateTime.from(toBeDeliveredOn, _location);
Expand Down

0 comments on commit caa1ccb

Please sign in to comment.