diff --git a/lib/pages/NotificationsPage.dart b/lib/pages/NotificationsPage.dart index c941394..2bfceb2 100644 --- a/lib/pages/NotificationsPage.dart +++ b/lib/pages/NotificationsPage.dart @@ -3,6 +3,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:ohthatsa/AppDrawer.dart'; import 'package:ohthatsa/main.dart'; +import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart'; +import 'package:ohthatsa/pages/practice/thing/PracticeThingAll.dart'; +import 'package:ohthatsa/pages/practice/thing/PracticeThingYear.dart'; + +import 'package:timezone/data/latest.dart' as tz; +import 'package:timezone/timezone.dart' as tz; class NotificationsPage extends StatefulWidget { @override @@ -25,7 +31,25 @@ class _NotificationPageState extends State { color: Colors.blue, textColor: Colors.white, onPressed: _notify - ) + ), + FlatButton( + child: Text("Schedule notification!"), + color: Colors.blue, + textColor: Colors.white, + onPressed: _scheduleNotify + ), + FlatButton( + child: Text("Waiting?"), + color: Colors.blue, + textColor: Colors.white, + onPressed: _checkPendingNotificationRequests + ), + FlatButton( + child: Text("Cancel"), + color: Colors.blue, + textColor: Colors.white, + onPressed: _cancelAllNotifications + ), ], ) ); @@ -39,10 +63,51 @@ class _NotificationPageState extends State { await flutterLocalNotificationsPlugin.show( 0, 'Title!', - 'and the body...', + 'and the body...\nnewline;alskdjf;leowijhfraojnfoeiurhowieurhlaskbjdfowiuehrpwqiuehrwiejhraowlijehbrwaoliuh?', platformChannelSpecifics, payload: "test item?" ); + } + Future _scheduleNotify() async { + PracticeThingAll pt = PracticeThingAll(); + + await flutterLocalNotificationsPlugin.zonedSchedule( + 0, + pt.dateFormatter.format(pt.current), + pt.weekdayFormatter.format(pt.current), + tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)), + const NotificationDetails( + android: AndroidNotificationDetails("id", "name", "desc") + ), + androidAllowWhileIdle: true, + uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, + matchDateTimeComponents: DateTimeComponents.time + ); + } + + Future _checkPendingNotificationRequests() async { + final List pendingNotificationRequests = + await flutterLocalNotificationsPlugin.pendingNotificationRequests(); + return showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + content: + Text('${pendingNotificationRequests.length} pending notification ' + 'requests'), + actions: [ + FlatButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + ), + ); + } + + Future _cancelAllNotifications() async { + await flutterLocalNotificationsPlugin.cancelAll(); } } \ No newline at end of file