some more notification stuff
This commit is contained in:
parent
3e7f15568e
commit
86a50e4f85
1 changed files with 67 additions and 2 deletions
|
@ -3,6 +3,12 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:ohthatsa/AppDrawer.dart';
|
import 'package:ohthatsa/AppDrawer.dart';
|
||||||
import 'package:ohthatsa/main.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 {
|
class NotificationsPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
@ -25,7 +31,25 @@ class _NotificationPageState extends State<NotificationsPage> {
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
onPressed: _notify
|
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(
|
await flutterLocalNotificationsPlugin.show(
|
||||||
0,
|
0,
|
||||||
'Title!',
|
'Title!',
|
||||||
'and the body...',
|
'and the body...\nnewline;alskdjf;leowijhfraojnfoeiurhowieurhlaskbjdfowiuehrpwqiuehrwiejhraowlijehbrwaoliuh?',
|
||||||
platformChannelSpecifics,
|
platformChannelSpecifics,
|
||||||
payload: "test item?"
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue