some more notification stuff

This commit is contained in:
BroodjeAap 2020-11-26 18:12:19 +01:00
parent 3e7f15568e
commit 86a50e4f85

View file

@ -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<NotificationsPage> {
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<NotificationsPage> {
await flutterLocalNotificationsPlugin.show(
0,
'Title!',
'and the body...',
'and the body...\nnewline;alskdjf;leowijhfraojnfoeiurhowieurhlaskbjdfowiuehrpwqiuehrwiejhraowlijehbrwaoliuh?',
platformChannelSpecifics,
payload: "test item?"
);
}
Future<void> _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<void> _checkPendingNotificationRequests() async {
final List<PendingNotificationRequest> pendingNotificationRequests =
await flutterLocalNotificationsPlugin.pendingNotificationRequests();
return showDialog<void>(
context: context,
builder: (BuildContext context) => AlertDialog(
content:
Text('${pendingNotificationRequests.length} pending notification '
'requests'),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
),
);
}
Future<void> _cancelAllNotifications() async {
await flutterLocalNotificationsPlugin.cancelAll();
}
}