2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 21:16:48 +00:00
inventree-app/lib/widget/notifications.dart
Oliver c9cad2f89f
Some checks failed
Android / build (push) Has been cancelled
CI / test (push) Has been cancelled
iOS / build (push) Has been cancelled
Change from fontawesome to tabler icons (#516)
* Change from fontawesome to tabler icons

- Consistent with the frontend

* Cleanup conflicts

* Use double quotes

* remove unused import

* Update release notes

* Migrate some google icons to tabler icons

* Icon update

* Properly support display of custom icons

* Fix lookup
2024-08-08 19:44:44 +10:00

107 lines
2.3 KiB
Dart

import "package:flutter/material.dart";
import "package:flutter_tabler_icons/flutter_tabler_icons.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 {
@override
_NotificationState createState() => _NotificationState();
}
class _NotificationState extends RefreshableState<NotificationWidget> {
_NotificationState() : super();
List<InvenTreeNotification> notifications = [];
bool isDismissing = false;
@override
String getAppBarTitle() => L10().notifications;
@override
Future<void> request (BuildContext context) async {
final results = await InvenTreeNotification().list();
notifications.clear();
for (InvenTreeModel n in results) {
if (n is InvenTreeNotification) {
notifications.add(n);
}
}
}
/*
* Dismiss an individual notification entry (mark it as "read")
*/
Future<void> dismissNotification(BuildContext context, InvenTreeNotification notification) async {
if (mounted) {
setState(() {
isDismissing = true;
});
} else {
return;
}
await notification.dismiss();
if (mounted) {
refresh(context);
setState(() {
isDismissing = false;
});
}
}
/*
* Display an individual notification message
*/
@override
List<Widget> getTiles(BuildContext context) {
List<Widget> tiles = [];
tiles.add(
ListTile(
title: Text(
L10().notifications,
),
subtitle: notifications.isEmpty ? Text(L10().notificationsEmpty) : null,
leading: notifications.isEmpty ? Icon(TablerIcons.bell_exclamation) : Icon(TablerIcons.bell),
trailing: Text("${notifications.length}"),
)
);
for (var notification in notifications) {
tiles.add(
ListTile(
title: Text(notification.name),
subtitle: Text(notification.message),
trailing: IconButton(
icon: Icon(TablerIcons.bookmark),
onPressed: isDismissing ? null : () async {
dismissNotification(context, notification);
},
),
)
);
}
return tiles;
}
}