2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-05-10 11:18:52 +00:00

Add model for notifications

- Display a list of active notifications
This commit is contained in:
Oliver Walters 2022-05-04 11:11:29 +10:00
parent b8857f2dbe
commit 6bbae67482
3 changed files with 75 additions and 6 deletions

@ -0,0 +1,31 @@
import "package:inventree/inventree/model.dart";
/*
* Class representing a "notification"
*/
class InvenTreeNotification extends InvenTreeModel {
InvenTreeNotification() : super();
InvenTreeNotification.fromJson(Map<String, dynamic> json) : super.fromJson(json);
@override
InvenTreeNotification createFromJson(Map<String, dynamic> json) {
return InvenTreeNotification.fromJson(json);
}
@override
String get URL => "notifications/";
String get message => (jsondata["message"] ?? "") as String;
DateTime? get creationDate {
if (jsondata.containsKey("creation")) {
return DateTime.tryParse((jsondata["creation"] ?? "") as String);
} else {
return null;
}
}
}

@ -467,6 +467,9 @@
"notifications": "Notifications",
"@notifications": {},
"notificationsEmpty": "No unread notifications",
"@notificationsEmpty": {},
"noResponse": "No Response from Server",
"@noResponse": {},

@ -1,8 +1,15 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:inventree/widget/refreshable_state.dart';
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
import "package:font_awesome_flutter/font_awesome_flutter.dart";
import "package:inventree/l10.dart";
import "package:inventree/inventree/model.dart";
import "package:inventree/inventree/notification.dart";
import "package:inventree/widget/refreshable_state.dart";
class NotificationWidget extends StatefulWidget {
@ -16,6 +23,8 @@ class _NotificationState extends RefreshableState<NotificationWidget> {
_NotificationState() : super();
List<InvenTreeNotification> notifications = [];
@override
AppBar? buildAppBar(BuildContext context) {
// No app bar for the notification widget
@ -24,7 +33,14 @@ class _NotificationState extends RefreshableState<NotificationWidget> {
@override
Future<void> request (BuildContext context) async {
print("requesting notifications!");
final results = await InvenTreeNotification().list();
for (InvenTreeModel n in results) {
if (n is InvenTreeNotification) {
notifications.add(n);
}
}
}
List<Widget> renderNotifications(BuildContext context) {
@ -33,11 +49,30 @@ class _NotificationState extends RefreshableState<NotificationWidget> {
tiles.add(
ListTile(
title: Text("Not"),
subtitle: Text("subtitle yatyayaya"),
title: Text(
L10().notifications,
),
subtitle: notifications.isEmpty ? Text(L10().notificationsEmpty) : null,
leading: notifications.isEmpty ? FaIcon(FontAwesomeIcons.bellSlash) : FaIcon(FontAwesomeIcons.bell),
trailing: Text("${notifications.length}"),
)
);
for (var notification in notifications) {
tiles.add(
ListTile(
title: Text(notification.name),
subtitle: Text(notification.message),
trailing: IconButton(
icon: FaIcon(FontAwesomeIcons.bookmark),
onPressed: () async {
},
),
)
);
}
return tiles;
}