-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
158 additions
and
10 deletions.
There are no files selected for viewing
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,10 @@ const DONE = 'Done'; | |
const CREATE = 'Create'; | ||
const FEEDBACK_EMAIL = '[email protected]'; | ||
const FEEDBACK = 'Feedback'; | ||
const NOTIFICATION_CHANNEL_ID = 'streak1'; | ||
const NOTIFICATION_CHANNEL_NAME = 'streak'; | ||
const NOTIFICATION_CHANNEL_DESCRIPTION = 'Notification for streak reminder'; | ||
const APP_LOGO = 'app_logo'; | ||
int currIndex = 0; | ||
String appVersion = '0.0.0'; | ||
var routes = <String, WidgetBuilder>{ | ||
|
@@ -124,7 +128,7 @@ Map<String, BucketCategory> stringToBucketCategory = { | |
}; | ||
|
||
Map<BucketCategory, String> bucketCategoryToString = { | ||
BucketCategory.travel: 'Travel', | ||
BucketCategory.travel: 'Travel', | ||
BucketCategory.finance: 'Finance', | ||
BucketCategory.adventure: 'Adventure', | ||
BucketCategory.career: 'Career', | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; | ||
import 'package:lifelist/constants/index.dart'; | ||
import 'package:lifelist/utils/utils.dart'; | ||
|
||
class NotificationService { | ||
static final NotificationService _notificationService = | ||
NotificationService._internal(); | ||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = | ||
FlutterLocalNotificationsPlugin(); | ||
factory NotificationService() { | ||
return _notificationService; | ||
} | ||
|
||
NotificationService._internal(); | ||
|
||
Future<void> init() async { | ||
const AndroidInitializationSettings initializationSettingsAndroid = | ||
AndroidInitializationSettings(APP_LOGO); | ||
|
||
const InitializationSettings initializationSettings = | ||
InitializationSettings( | ||
android: initializationSettingsAndroid, iOS: null, macOS: null); | ||
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); | ||
bool? isPermissionGranted = await flutterLocalNotificationsPlugin | ||
.resolvePlatformSpecificImplementation< | ||
AndroidFlutterLocalNotificationsPlugin>() | ||
?.requestPermission(); | ||
if (isPermissionGranted == true) { | ||
await flutterLocalNotificationsPlugin.initialize(initializationSettings); | ||
} | ||
} | ||
|
||
void scheduleNotification(String title, String body, int id, bool isCompleted, | ||
DateTime deadline) async { | ||
final timeToNotify = getNotificationScheduleTime(deadline, isCompleted); | ||
await flutterLocalNotificationsPlugin.zonedSchedule( | ||
id, | ||
title, | ||
body, | ||
timeToNotify, | ||
const NotificationDetails( | ||
android: AndroidNotificationDetails( | ||
NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, | ||
channelDescription: NOTIFICATION_CHANNEL_DESCRIPTION)), | ||
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, | ||
uiLocalNotificationDateInterpretation: | ||
UILocalNotificationDateInterpretation.absoluteTime); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
import 'package:timezone/data/latest_all.dart' as tz; | ||
import 'package:timezone/timezone.dart' as tz; | ||
|
||
int daysBetween(DateTime froms, DateTime to) { | ||
froms = DateTime(froms.year, froms.month, froms.day); | ||
to = DateTime(to.year, to.month, to.day); | ||
return (to.difference(froms).inHours / 24).round(); | ||
} | ||
|
||
tz.TZDateTime getNotificationScheduleTime(DateTime deadline, bool isCompleted) { | ||
final timeZoneName = tz.TimeZone.UTC.abbreviation; | ||
tz.initializeTimeZones(); | ||
tz.setLocalLocation(tz.getLocation(timeZoneName)); | ||
tz.Location location = tz.getLocation(timeZoneName); | ||
final scheduledDate = tz.TZDateTime.from(deadline, location); | ||
tz.TZDateTime timeToNotify = isCompleted | ||
? scheduledDate.add(const Duration(hours: 23)) | ||
: scheduledDate.subtract(const Duration(hours: 1)); | ||
return timeToNotify; | ||
} |
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
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