Created
April 16, 2019 19:06
-
-
Save jesusrp98/7f19984788f10c243107b2c5bc51c4e1 to your computer and use it in GitHub Desktop.
Schedules notifications if neccesary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future initNotifications(BuildContext context) async { | |
bool updateNotifications; | |
final SharedPreferences prefs = await SharedPreferences.getInstance(); | |
// Checks if is necessary to update scheduled notifications | |
try { | |
updateNotifications = | |
prefs.getString('notifications.launches.upcoming') != | |
launch.launchDate.toIso8601String(); | |
} catch (e) { | |
updateNotifications = true; | |
} | |
// Update notifications if necessary | |
if (updateNotifications) { | |
// T - 1 day notification | |
await _scheduleNotification( | |
id: 0, | |
context: context, | |
time: FlutterI18n.translate( | |
context, | |
'spacex.notifications.launches.time_tomorrow', | |
), | |
subtract: Duration(days: 1), | |
); | |
// Update storaged launch date | |
prefs.setString( | |
'notifications.launches.upcoming', | |
launch.launchDate.toIso8601String(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment