NotificationHandler class abstract
A utility class for handling and processing notifications.
The NotificationHandler
provides methods to register handlers for specific types
of notifications and to process incoming notifications by routing them to the
appropriate handler.
Example
// Create a handler for the NotificationHandler
final notificationHandler = NotificationHandler();
// Register handlers for different notification types
notificationHandler.registerHandler<TextNotification>((notification) {
print('Received text notification: ${notification.text}');
});
notificationHandler.registerHandler<ImageNotification>((notification) {
print('Received image notification with URL: ${notification.imageUrl}');
});
// Process incoming notifications
final textNotif = TextNotification('Hello, world!');
notificationHandler.handle(textNotif); // Prints: Received text notification: Hello, world!
final imageNotif = ImageNotification('https://example.com/image.jpg');
notificationHandler.handle(imageNotif); // Prints: Received image notification with URL: https://example.com/image.jpg
This pattern allows for decoupling notification processing logic and handling different notification types without complex conditional statements.
Constructors
- NotificationHandler.new(BuildContext context)
Properties
- context → BuildContext
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
handle(
UserNotification userNofication) → FutureOr< void> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited