got full screen notification working, doesn't wake up the device yet, but payload is delivered and right pizza event/recipe step is fetched
This commit is contained in:
parent
41b003acb7
commit
eb20ae24c0
4 changed files with 104 additions and 20 deletions
|
@ -39,7 +39,8 @@ class PizzaEvent extends HiveObject{
|
||||||
"PizzaEventChannel", "PizzaEventChannel", "PizzaPlanner notification channel",
|
"PizzaEventChannel", "PizzaEventChannel", "PizzaPlanner notification channel",
|
||||||
importance: Importance.max,
|
importance: Importance.max,
|
||||||
priority: Priority.high,
|
priority: Priority.high,
|
||||||
ticker: "ticker"
|
ticker: "ticker",
|
||||||
|
fullScreenIntent: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics);
|
const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics);
|
||||||
|
@ -53,20 +54,22 @@ class PizzaEvent extends HiveObject{
|
||||||
final List<PendingNotificationRequest> pendingNotificationRequests = await flutterLocalNotificationsPlugin.pendingNotificationRequests();
|
final List<PendingNotificationRequest> pendingNotificationRequests = await flutterLocalNotificationsPlugin.pendingNotificationRequests();
|
||||||
int notificationId = pendingNotificationRequests.map((pendingNotification) => pendingNotification.id).fold(0, max);
|
int notificationId = pendingNotificationRequests.map((pendingNotification) => pendingNotification.id).fold(0, max);
|
||||||
|
|
||||||
|
int stepId = 0;
|
||||||
for (var recipeStep in this.recipe.recipeSteps) {
|
for (var recipeStep in this.recipe.recipeSteps) {
|
||||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||||
notificationId,
|
notificationId+stepId,
|
||||||
recipeStep.name,
|
recipeStep.name,
|
||||||
null,
|
null,
|
||||||
stepTime,
|
stepTime,
|
||||||
platformChannelSpecific,
|
platformChannelSpecific,
|
||||||
androidAllowWhileIdle: true,
|
androidAllowWhileIdle: true,
|
||||||
|
payload: "${this.key}__$stepId",
|
||||||
uiLocalNotificationDateInterpretation:
|
uiLocalNotificationDateInterpretation:
|
||||||
UILocalNotificationDateInterpretation.absoluteTime
|
UILocalNotificationDateInterpretation.absoluteTime
|
||||||
);
|
);
|
||||||
recipeStep.notificationId = notificationId;
|
recipeStep.notificationId = notificationId;
|
||||||
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
||||||
notificationId++;
|
stepId++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,17 +8,22 @@ import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
||||||
import 'package:pizzaplanner/pages/AddPizzaEventPage.dart';
|
import 'package:pizzaplanner/pages/AddPizzaEventPage.dart';
|
||||||
import 'package:pizzaplanner/pages/PickPizzaRecipePage.dart';
|
import 'package:pizzaplanner/pages/PickPizzaRecipePage.dart';
|
||||||
|
import 'package:pizzaplanner/pages/PizzaEventNotificationPage.dart';
|
||||||
import 'package:pizzaplanner/pages/PizzaEventPage.dart';
|
import 'package:pizzaplanner/pages/PizzaEventPage.dart';
|
||||||
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:pizzaplanner/util.dart';
|
import 'package:pizzaplanner/util.dart';
|
||||||
|
import 'package:rxdart/subjects.dart';
|
||||||
|
|
||||||
import 'package:timezone/data/latest.dart' as tz;
|
import 'package:timezone/data/latest.dart' as tz;
|
||||||
import 'package:timezone/timezone.dart' as tz;
|
import 'package:timezone/timezone.dart' as tz;
|
||||||
|
|
||||||
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||||
|
final BehaviorSubject<String?> selectNotificationSubject = BehaviorSubject<String?>();
|
||||||
|
String? selectedNotificationPayload;
|
||||||
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
// hive init
|
// hive init
|
||||||
|
@ -47,28 +52,51 @@ void main() async {
|
||||||
iOS: initializationSettingsIOS,
|
iOS: initializationSettingsIOS,
|
||||||
macOS: initializationSettingsMacOS
|
macOS: initializationSettingsMacOS
|
||||||
);
|
);
|
||||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
onSelectNotification: selectNotification);
|
initializationSettings,
|
||||||
|
onSelectNotification: (String? payload) async {
|
||||||
|
selectedNotificationPayload = payload;
|
||||||
|
selectNotificationSubject.add(payload);
|
||||||
|
});
|
||||||
|
|
||||||
// init timezones properly
|
// init timezones properly
|
||||||
tz.initializeTimeZones();
|
tz.initializeTimeZones();
|
||||||
final String? timeZoneName = await FlutterNativeTimezone.getLocalTimezone();
|
final String? timeZoneName = await FlutterNativeTimezone.getLocalTimezone();
|
||||||
tz.setLocalLocation(tz.getLocation(timeZoneName!));
|
tz.setLocalLocation(tz.getLocation(timeZoneName!));
|
||||||
|
|
||||||
runApp(PizzaPlanner());
|
runApp(
|
||||||
|
MaterialApp(
|
||||||
|
title: "PizzaPlanner",
|
||||||
|
home: PizzaPlanner(),
|
||||||
|
onGenerateRoute: RouteGenerator.generateRoute,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
//await Hive.close();
|
//await Hive.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
class PizzaPlanner extends StatelessWidget {
|
class PizzaPlanner extends StatefulWidget {
|
||||||
// This widget is the root of your application.
|
@override
|
||||||
|
PizzaPlannerState createState() => PizzaPlannerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class PizzaPlannerState extends State<PizzaPlanner> {
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState(){
|
||||||
|
super.initState();
|
||||||
|
this._configureSelectNotificationSubject();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return PizzaEventsPage();
|
||||||
title: "PizzaPlanner",
|
}
|
||||||
home: PizzaEventsPage(),
|
|
||||||
onGenerateRoute: RouteGenerator.generateRoute,
|
void _configureSelectNotificationSubject() {
|
||||||
);
|
selectNotificationSubject.stream.listen((String? payload) async {
|
||||||
|
await Navigator.pushNamed(context, '/event/notification', arguments: payload);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +115,9 @@ class RouteGenerator {
|
||||||
case "/event/view": {
|
case "/event/view": {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventPage(settings.arguments as PizzaEvent));
|
return MaterialPageRoute(builder: (context) => PizzaEventPage(settings.arguments as PizzaEvent));
|
||||||
}
|
}
|
||||||
|
case "/event/notification": {
|
||||||
|
return MaterialPageRoute(builder: (context) => PizzaEventNotificationPage(settings.arguments as String?));
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
||||||
|
@ -95,10 +126,3 @@ class RouteGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future selectNotification(String? payload) async {
|
|
||||||
if (payload == null) {
|
|
||||||
print("Payload: null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
print("Payload: $payload");
|
|
||||||
}
|
|
55
lib/pages/PizzaEventNotificationPage.dart
Normal file
55
lib/pages/PizzaEventNotificationPage.dart
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||||
|
|
||||||
|
class PizzaEventNotificationPage extends StatefulWidget {
|
||||||
|
final String? payload;
|
||||||
|
|
||||||
|
PizzaEventNotificationPage(this.payload);
|
||||||
|
|
||||||
|
@override
|
||||||
|
PizzaEventNotificationState createState() => PizzaEventNotificationState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
|
||||||
|
late final PizzaEvent pizzaEvent;
|
||||||
|
late final RecipeStep recipeStep;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (this.widget.payload == null){
|
||||||
|
print("Redirected to notification page but no payload... Popping");
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
var split = this.widget.payload!.split("__");
|
||||||
|
var pizzaEventId = int.parse(split[0]);
|
||||||
|
var recipeStepId = int.parse(split[1]);
|
||||||
|
|
||||||
|
var pizzaEventsBox = Hive.box<PizzaEvent>("PizzaEvents");
|
||||||
|
|
||||||
|
pizzaEvent = pizzaEventsBox.get(pizzaEventId)!;
|
||||||
|
recipeStep = pizzaEvent.recipe.recipeSteps[recipeStepId];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text("From notification"),
|
||||||
|
),
|
||||||
|
resizeToAvoidBottomInset: false,
|
||||||
|
body: Container(
|
||||||
|
padding: EdgeInsets.fromLTRB(40, 10, 40, 10),
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Text(pizzaEvent.name),
|
||||||
|
Text(recipeStep.name)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,6 +38,8 @@ dependencies:
|
||||||
hive: ^2.0.4
|
hive: ^2.0.4
|
||||||
hive_flutter: ^1.1.0
|
hive_flutter: ^1.1.0
|
||||||
|
|
||||||
|
rxdart: ^0.27.1
|
||||||
|
|
||||||
timezone: ^0.7.0
|
timezone: ^0.7.0
|
||||||
flutter_native_timezone: ^2.0.0
|
flutter_native_timezone: ^2.0.0
|
||||||
flutter_local_notifications: ^8.0.0
|
flutter_local_notifications: ^8.0.0
|
||||||
|
|
Loading…
Add table
Reference in a new issue