mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 13:25:40 +00:00 
			
		
		
		
	Add model for notifications
- Display a list of active notifications
This commit is contained in:
		
							
								
								
									
										31
									
								
								lib/inventree/notification.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								lib/inventree/notification.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -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": "Notifications", | ||||||
|   "@notifications": {}, |   "@notifications": {}, | ||||||
|  |  | ||||||
|  |    "notificationsEmpty": "No unread notifications", | ||||||
|  |    "@notificationsEmpty": {}, | ||||||
|  |  | ||||||
|   "noResponse": "No Response from Server", |   "noResponse": "No Response from Server", | ||||||
|   "@noResponse": {}, |   "@noResponse": {}, | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,8 +1,15 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
| import 'package:flutter/cupertino.dart'; | import "package:flutter/cupertino.dart"; | ||||||
| import 'package:flutter/material.dart'; | import "package:flutter/material.dart"; | ||||||
| import 'package:inventree/widget/refreshable_state.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 { | class NotificationWidget extends StatefulWidget { | ||||||
|  |  | ||||||
| @@ -16,6 +23,8 @@ class _NotificationState extends RefreshableState<NotificationWidget> { | |||||||
|  |  | ||||||
|   _NotificationState() : super(); |   _NotificationState() : super(); | ||||||
|  |  | ||||||
|  |   List<InvenTreeNotification> notifications = []; | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   AppBar? buildAppBar(BuildContext context) { |   AppBar? buildAppBar(BuildContext context) { | ||||||
|     // No app bar for the notification widget |     // No app bar for the notification widget | ||||||
| @@ -24,7 +33,14 @@ class _NotificationState extends RefreshableState<NotificationWidget> { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Future<void> request (BuildContext context) async { |   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) { |   List<Widget> renderNotifications(BuildContext context) { | ||||||
| @@ -33,11 +49,30 @@ class _NotificationState extends RefreshableState<NotificationWidget> { | |||||||
|  |  | ||||||
|     tiles.add( |     tiles.add( | ||||||
|       ListTile( |       ListTile( | ||||||
|         title: Text("Not"), |         title: Text( | ||||||
|         subtitle: Text("subtitle yatyayaya"), |           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; |     return tiles; | ||||||
|  |  | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user