Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Created February 5, 2025 00:56
Show Gist options
  • Save lukepighetti/df652168b35eb9d21208f3bcf7e16ed4 to your computer and use it in GitHub Desktop.
Save lukepighetti/df652168b35eb9d21208f3bcf7e16ed4 to your computer and use it in GitHub Desktop.
class NotificationController extends SimpleNotifications {
DateTime? trialExpiring = DateTime(2025, 2, 7, 6);
var winback = true;
var remindWorkouts = true;
var aiGirlfriendMessages = {
Duration(hours: 1): "whats up?",
Duration(hours: 2): "where are you?",
Duration(hours: 3): "do you still love me??",
};
List<Notification> get notifications => [
if (remindWorkouts)
for (final h in [6, 12, 17])
Notification(
title: "Log your workout!",
schedule: Schedule.every(
const Duration(days: 1),
starting: DateTime.now().copyWith(hour: h),
time: Time.wallClock(),
),
),
if (winback)
Notification(
title: "We have a discount for you!",
urgency: Urgency.high,
schedule: Schedule.afterBackground(
delay: const Duration(seconds: 5),
),
),
for (final MapEntry(key: d, value: m) in aiGirlfriendMessages.entries)
Notification(
title: "Sheila",
subtitle: m,
schedule: Schedule.afterBackground(
delay: d,
),
),
if (trialExpiring != null)
Notification(
title: "Your trial is about to expire",
urgency: Urgency.subtle,
schedule: Schedule.once(
at: trialExpiring!.subtract(const Duration(hours: 1)),
time: Time.actual(),
),
),
];
void update() => scheduleNotifications();
}
abstract class SimpleNotifications {
List<Notification> get notifications;
void scheduleNotifications() {}
}
class Notification {
Notification({
String? title,
String? subtitle,
Enum? priority,
bool? sound,
bool? vibrate,
Schedule? schedule,
Urgency? urgency,
});
}
class Schedule {
Schedule.once({
DateTime? at,
Time? time,
});
Schedule.every(
Duration interval, {
DateTime? starting,
Time? time,
});
Schedule.afterBackground({
Duration? delay,
});
}
class Time {
Time.wallClock();
Time.actual();
}
enum Urgency {
high,
normal,
subtle,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment