mirror of
https://github.com/inventree/inventree-app.git
synced 2025-07-21 20:56:32 +00:00
.github
android
assets
ios
lib
generated
inventree
l10n
settings
widget
attachment_widget.dart
back.dart
bom_list.dart
category_display.dart
category_list.dart
company_detail.dart
company_list.dart
dialogs.dart
drawer.dart
fields.dart
home.dart
location_display.dart
location_list.dart
notifications.dart
paginator.dart
part_detail.dart
part_image_widget.dart
part_list.dart
part_notes.dart
part_suppliers.dart
progress.dart
purchase_order_detail.dart
purchase_order_list.dart
refreshable_state.dart
search.dart
snacks.dart
spinner.dart
stock_detail.dart
stock_item_history.dart
stock_item_test_results.dart
stock_list.dart
stock_notes.dart
api.dart
api_form.dart
app_colors.dart
barcode.dart
dummy_dsn.dart
helpers.dart
l10.dart
main.dart
preferences.dart
user_profile.dart
res
test
.gitignore
.gitmodules
.metadata
LICENSE
README.md
RELEASE.md
analysis_options.yaml
crowdin.yml
find_dart_files.py
l10n.yaml
pubspec.lock
pubspec.yaml
requirements.txt
- Simplify implementation - Create mixin class for code reuse - Allow custom app-bar - Allow custom ordering / sorting options - Improve code commenting / readability
100 lines
2.3 KiB
Dart
100 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
|
|
AppBar? buildAppBar(BuildContext context, GlobalKey<ScaffoldState> key) {
|
|
// No app bar for the notification widget
|
|
return null;
|
|
}
|
|
|
|
@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);
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> dismissNotification(BuildContext context, InvenTreeNotification notification) async {
|
|
|
|
await notification.dismiss();
|
|
|
|
refresh(context);
|
|
|
|
}
|
|
|
|
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()
|
|
)
|
|
);
|
|
}
|
|
|
|
} |