Add actionable notifications
This commit is contained in:
@ -46,7 +46,7 @@ android {
|
|||||||
applicationId "haus.nightmare.tbdoctor"
|
applicationId "haus.nightmare.tbdoctor"
|
||||||
// You can update the following values to match your application needs.
|
// You can update the following values to match your application needs.
|
||||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
|
||||||
minSdkVersion flutter.minSdkVersion
|
minSdkVersion 21
|
||||||
targetSdkVersion flutter.targetSdkVersion
|
targetSdkVersion flutter.targetSdkVersion
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|||||||
@ -7,14 +7,38 @@ import 'package:intl/intl.dart';
|
|||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||||
|
import 'package:scheduled_timer/scheduled_timer.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
AwesomeNotifications().initialize(
|
||||||
|
// set the icon to null if you want to use the default app icon
|
||||||
|
null,
|
||||||
|
[
|
||||||
|
NotificationChannel(
|
||||||
|
channelGroupKey: 'reminder_channel_group',
|
||||||
|
channelKey: 'reminder_channel',
|
||||||
|
channelName: 'Check-In Reminder notifications',
|
||||||
|
channelDescription: 'Notification channel for Check-In Reminders',
|
||||||
|
defaultColor: Colors.cyan.shade900,
|
||||||
|
ledColor: Colors.white)
|
||||||
|
],
|
||||||
|
// Channel groups are only visual and are not required
|
||||||
|
channelGroups: [
|
||||||
|
NotificationChannelGroup(
|
||||||
|
channelGroupkey: 'reminder_channel_group',
|
||||||
|
channelGroupName: 'Reminder group')
|
||||||
|
],
|
||||||
|
debug: true
|
||||||
|
);
|
||||||
runApp(const TBDoctor());
|
runApp(const TBDoctor());
|
||||||
}
|
}
|
||||||
|
|
||||||
class TBDoctor extends StatelessWidget {
|
class TBDoctor extends StatelessWidget {
|
||||||
const TBDoctor({Key? key}) : super(key: key);
|
const TBDoctor({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
get id => null;
|
||||||
|
|
||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -115,6 +139,7 @@ class _TBDoctorHomePageState extends State<TBDoctorHomePage> {
|
|||||||
|
|
||||||
// Required for program
|
// Required for program
|
||||||
late SharedPreferences _prefs;
|
late SharedPreferences _prefs;
|
||||||
|
late ScheduledTimer checkinReminder;
|
||||||
|
|
||||||
void _setCalcs() async {
|
void _setCalcs() async {
|
||||||
if (_inOfficeHoursToDate == 0.0 && _tbdHoursToDate == 0.0 ||
|
if (_inOfficeHoursToDate == 0.0 && _tbdHoursToDate == 0.0 ||
|
||||||
@ -313,6 +338,24 @@ class _TBDoctorHomePageState extends State<TBDoctorHomePage> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
void _showReminderNotification() {
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
if (now.weekday == DateTime.saturday || now.weekday == DateTime.sunday) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AwesomeNotifications().createNotification(
|
||||||
|
content: NotificationContent(
|
||||||
|
id: 10,
|
||||||
|
channelKey: 'reminder_channel',
|
||||||
|
title: 'Check-In Reminder',
|
||||||
|
body: 'Are you remote, in office, or out today?'),
|
||||||
|
actionButtons: <NotificationActionButton>[
|
||||||
|
NotificationActionButton(key: 'remote', label: 'Remote'),
|
||||||
|
NotificationActionButton(key: 'office', label: 'In Office'),
|
||||||
|
NotificationActionButton(key: 'no', label: 'Not Today'),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -324,6 +367,57 @@ class _TBDoctorHomePageState extends State<TBDoctorHomePage> {
|
|||||||
_setCalcs();
|
_setCalcs();
|
||||||
_populateSelf();
|
_populateSelf();
|
||||||
});
|
});
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
checkinReminder = ScheduledTimer(
|
||||||
|
id: "checkinReminder",
|
||||||
|
onExecute: _showReminderNotification,
|
||||||
|
defaultScheduledTime: DateTime(now.year, now.month, now.day + 1, 7, 0),
|
||||||
|
onMissedSchedule: _showReminderNotification,
|
||||||
|
);
|
||||||
|
|
||||||
|
AwesomeNotifications().actionStream.listen((receivedNotification) {
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
double hours = 7.5;
|
||||||
|
if (now.weekday == DateTime.saturday || now.weekday == DateTime.sunday) {
|
||||||
|
debugPrint("Detected weekend, no work allowed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (now.isAfter(DateTime(now.year, 06, 23)) || now.isBefore(DateTime(now.year, 09, 14))) {
|
||||||
|
debugPrint("Detected summer hours");
|
||||||
|
hours = 8;
|
||||||
|
if (now.weekday == DateTime.friday) {
|
||||||
|
debugPrint("Detected summer hours, half day friday");
|
||||||
|
hours = 4.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SharedPreferences.getInstance().then((SharedPreferences p) {
|
||||||
|
_prefs = p;
|
||||||
|
switch(receivedNotification.buttonKeyPressed) {
|
||||||
|
case "remote":
|
||||||
|
debugPrint("Modifying TBD since user responded 'remote'");
|
||||||
|
_tbdHoursToDate += hours;
|
||||||
|
_prefs.setDouble("_tbdHoursToDate", _tbdHoursToDate);
|
||||||
|
break;
|
||||||
|
case "office":
|
||||||
|
debugPrint("Modifying in-office since user responded 'office'");
|
||||||
|
_inOfficeHoursToDate += hours;
|
||||||
|
_prefs.setDouble("_tbdHoursToDate", _tbdHoursToDate);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
debugPrint("Didn't care.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Schedule the next one?
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
checkinReminder = ScheduledTimer(
|
||||||
|
id: "checkinReminder",
|
||||||
|
onExecute: _showReminderNotification,
|
||||||
|
defaultScheduledTime: DateTime(now.year, now.month, now.day + 1, 7, 0),
|
||||||
|
onMissedSchedule: _showReminderNotification,
|
||||||
|
);
|
||||||
|
_setCalcs();
|
||||||
|
});
|
||||||
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
pubspec.lock
14
pubspec.lock
@ -22,6 +22,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.8.2"
|
version: "2.8.2"
|
||||||
|
awesome_notifications:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: awesome_notifications
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.21"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -240,6 +247,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.2.4"
|
version: "4.2.4"
|
||||||
|
scheduled_timer:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: scheduled_timer
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@ -36,6 +36,8 @@ dependencies:
|
|||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
shared_preferences: ^2.0.15
|
shared_preferences: ^2.0.15
|
||||||
|
awesome_notifications: any
|
||||||
|
scheduled_timer: ^2.0.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user