2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00
inventree-app/lib/widget/notifications.dart
Oliver a8f87e2f5a
UX Overhaul (#300)
* Add "global actions" to title bar

* Implement actions

* Add "speed dial" action buttons

* tweak global action icons

* Refactor actions for "stock item" display

* Refactor "part" detail

* part category

* SupplierPart

* More updates

* Add BottomAppBar

* Add a global bottom app bar

* Move "edit" buttons back to the app bar

* tweaks

* Updates to drawer navigation menu

* home screen improvements

* text tweaks

* Fix appBarTitle for notifications widget

* Update "tabs" for category display

* Fix for attachment widget

* Update tabs for purchaseorder view

* Update part display

* Cleanup

* Add "BOM" tab to part detail widget

* Paginated list search cleanup

* Update release notes

* Update old function

* linting

* linting

* Tweaks to bottomappbar

- Increase icon size slightly
- Adjust "actions" icon
2023-04-08 23:59:11 +10:00

103 lines
2.3 KiB
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 {
@override
_NotificationState createState() => _NotificationState();
}
class _NotificationState extends RefreshableState<NotificationWidget> {
_NotificationState() : super();
List<InvenTreeNotification> notifications = [];
@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 {
await notification.dismiss();
refresh(context);
}
/*
* Display an individual notification message
*/
List<Widget> renderNotifications(BuildContext context) {
List<Widget> tiles = [];
tiles.add(
ListTile(
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 {
dismissNotification(context, notification);
},
),
)
);
}
return tiles;
}
@override
Widget getBody(BuildContext context) {
return Center(
child: ListView(
children: ListTile.divideTiles(
context: context,
tiles: renderNotifications(context),
).toList()
)
);
}
}