9class NotificationManagerExample {
11 LocationManager? _locationManager;
12 NotificationManager? _notificationManager;
13 NotificationListener? _notificationListener;
15 NotificationManagerExample() {
17 _setupNotificationListener();
23 void _initializeSdk() {
27 _sdk = NavigineSdk.getInstance();
32 _sdk?.setUserHash(
"USER-HASH-HERE");
37 _sdk?.setServer(
"https://custom.navigine.com");
42 _locationManager = _sdk?.getLocationManager();
47 _notificationManager = _sdk?.getNotificationManager(_locationManager!);
50 if (_locationManager !=
null && _notificationManager !=
null) {
51 print(
"LocationManager and NotificationManager successfully initialized");
54 print(
"Error initializing SDK: $e");
61 void _setupNotificationListener() {
62 _notificationListener = NotificationListener(
64 onNotificationLoaded: (Notification notification) {
65 print(
"Notification loaded");
66 _demonstrateNotificationUsage(notification);
71 onNotificationFailed: (Error error) {
72 print(
"Notification failed: ${error.message}");
73 _demonstrateErrorHandling(error);
82 void demonstrateNotificationManagerMethods() {
83 if (_notificationManager ==
null) {
84 print(
"NotificationManager not initialized");
90 _notificationManager!.addNotificationListener(_notificationListener!);
91 print(
"Added notification listener");
95 Future.delayed(Duration(seconds: 2), () {
98 _notificationManager!.removeNotificationListener(_notificationListener!);
99 print(
"Removed notification listener");
107 void _demonstrateNotificationUsage(Notification notification) {
108 if (notification ==
null) {
109 print(
"Notification is null");
115 int id = notification.id;
116 print(
"Notification ID: $id");
121 String title = notification.title;
122 print(
"Notification title: $title");
127 String content = notification.content;
128 print(
"Notification content: $content");
133 String? imageUrl = notification.imageUrl;
134 if (imageUrl !=
null) {
135 print(
"Notification image URL: $imageUrl");
137 print(
"Notification has no image URL");
145 void _demonstrateErrorHandling(Error error) {
146 print(
"Handling notification error:");
147 print(
" Error message: ${error.message}");
148 print(
" Error type: ${error.runtimeType}");
154 Future<void> runExample() async {
155 print(
"=== NotificationManager Example ===");
157 demonstrateNotificationManagerMethods();
160 await Future.delayed(Duration(seconds: 5));
162 print(
"=== Example completed ===");