Loading...
Searching...
No Matches
navigine_sdk_example.dart
Go to the documentation of this file.
1import 'package:navigine_sdk/navigine_sdk.dart';
2
7class NavigineSdkExample {
19
20 NavigineSdkExample() {
21 _initializeSdk();
22 }
23
27 void _initializeSdk() {
28 try {
29 // [dart_NavigineSdk_getInstance]
30 // Get SDK instance
32 // [dart_NavigineSdk_getInstance]
33
34 // [dart_NavigineSdk_getVersion]
35 // Get SDK version
36 print('Navigine SDK Version: ${NavigineSdk.getVersion()}');
37 // [dart_NavigineSdk_getVersion]
38
39 // [dart_NavigineSdk_getDeviceId]
40 // Get device ID
41 print('Device ID: ${NavigineSdk.getDeviceId()}');
42 // [dart_NavigineSdk_getDeviceId]
43
44 // [dart_NavigineSdk_getRelativeTime]
45 // Get relative time
46 print('Relative Time: ${NavigineSdk.getRelativeTime()}');
47 // [dart_NavigineSdk_getRelativeTime]
48
49 // [dart_NavigineSdk_setUserHash]
50 // Set user hash (authorization token)
51 _sdk?.setUserHash('XXXX-XXXX-XXXX-XXXX');
52 // [dart_NavigineSdk_setUserHash]
53
54 // [dart_NavigineSdk_setServer]
55 // Set server URL (optional)
56 _sdk?.setServer('https://custom.navigine.com');
57 // [dart_NavigineSdk_setServer]
58
59 // Initialize managers
60 _initializeManagers();
61 } catch (e) {
62 print('SDK initialization error: $e');
63 }
64 }
65
69 void _initializeManagers() {
70 // [dart_NavigineSdk_getLocationManager]
71 // Get LocationManager for working with locations
72 _locationManager = _sdk?.getLocationManager();
73 if (_locationManager != null) {
74 print('LocationManager successfully initialized');
75 }
76 // [dart_NavigineSdk_getLocationManager]
77
78 // [dart_NavigineSdk_getNavigationManager]
79 // Get NavigationManager for navigation
80 if (_locationManager != null) {
81 _navigationManager = _sdk?.getNavigationManager(_locationManager!);
82 if (_navigationManager != null) {
83 print('NavigationManager successfully initialized');
84 }
85 }
86 // [dart_NavigineSdk_getNavigationManager]
87
88 // [dart_NavigineSdk_getZoneManager]
89 // Get ZoneManager for working with zones
90 if (_navigationManager != null) {
91 _zoneManager = _sdk?.getZoneManager(_navigationManager!);
92 if (_zoneManager != null) {
93 print('ZoneManager successfully initialized');
94 }
95 }
96 // [dart_NavigineSdk_getZoneManager]
97
98 // [dart_NavigineSdk_getRouteManager]
99 // Get RouteManager for building routes
100 if (_locationManager != null && _navigationManager != null) {
101 _routeManager = _sdk?.getRouteManager(
104 );
105 if (_routeManager != null) {
106 print('RouteManager successfully initialized');
107 }
108 }
109 // [dart_NavigineSdk_getRouteManager]
110
111 // [dart_NavigineSdk_getAsyncRouteManager]
112 // Get AsyncRouteManager for async route operations
113 if (_locationManager != null && _navigationManager != null) {
114 _asyncRouteManager = _sdk?.getAsyncRouteManager(
117 );
118 if (_asyncRouteManager != null) {
119 print('AsyncRouteManager successfully initialized');
120 }
121 }
122 // [dart_NavigineSdk_getAsyncRouteManager]
123
124 // [dart_NavigineSdk_getNotificationManager]
125 // Get NotificationManager for notifications
126 if (_locationManager != null) {
127 _notificationManager = _sdk?.getNotificationManager(_locationManager!);
128 if (_notificationManager != null) {
129 print('NotificationManager successfully initialized');
130 }
131 }
132 // [dart_NavigineSdk_getNotificationManager]
133
134 // [dart_NavigineSdk_getMeasurementManager]
135 // Get MeasurementManager for measurements
136 if (_locationManager != null) {
137 _measurementManager = _sdk?.getMeasurementManager(_locationManager!);
138 if (_measurementManager != null) {
139 print('MeasurementManager successfully initialized');
140 }
141 }
142 // [dart_NavigineSdk_getMeasurementManager]
143
144 // [dart_NavigineSdk_getLocationListManager]
145 // Get LocationListManager for location list operations
146 _locationListManager = _sdk?.getLocationListManager();
147 if (_locationListManager != null) {
148 print('LocationListManager successfully initialized');
149 }
150 // [dart_NavigineSdk_getLocationListManager]
151
152 // [dart_NavigineSdk_getStorageManager]
153 // Get StorageManager for working with storages
154 _storageManager = _sdk?.getStorageManager();
155 if (_storageManager != null) {
156 print('StorageManager successfully initialized');
157 }
158 // [dart_NavigineSdk_getStorageManager]
159
160 // [dart_NavigineSdk_getMqttSession]
161 // Get MqttSession for publishing position data via MQTT
162 if (_navigationManager != null) {
163 _mqttSession = _sdk?.getMqttSession(_navigationManager!);
164 if (_mqttSession != null) {
165 print('MqttSession successfully initialized');
166 }
167 }
168 // [dart_NavigineSdk_getMqttSession]
169 }
170
174 void printSdkInfo() {
175 print('=== Navigine SDK Information ===');
176 print('SDK Version: ${NavigineSdk.getVersion()}');
177 print('Device ID: ${NavigineSdk.getDeviceId()}');
178 print('Relative Time: ${NavigineSdk.getRelativeTime()}');
179 print(
180 'LocationManager: ${_locationManager != null ? "available" : "unavailable"}',
181 );
182 print(
183 'NavigationManager: ${_navigationManager != null ? "available" : "unavailable"}',
184 );
185 print('ZoneManager: ${_zoneManager != null ? "available" : "unavailable"}');
186 print(
187 'RouteManager: ${_routeManager != null ? "available" : "unavailable"}',
188 );
189 print(
190 'AsyncRouteManager: ${_asyncRouteManager != null ? "available" : "unavailable"}',
191 );
192 print(
193 'NotificationManager: ${_notificationManager != null ? "available" : "unavailable"}',
194 );
195 print(
196 'MeasurementManager: ${_measurementManager != null ? "available" : "unavailable"}',
197 );
198 print(
199 'LocationListManager: ${_locationListManager != null ? "available" : "unavailable"}',
200 );
201 print(
202 'StorageManager: ${_storageManager != null ? "available" : "unavailable"}',
203 );
204 print(
205 'MqttSession: ${_mqttSession != null ? "available" : "unavailable"}',
206 );
207 }
208
213 print('=== Manager Usage Demonstration ===');
214
215 // LocationManager usage example
216 if (_locationManager != null) {
217 print('LocationManager ready for location operations');
218 // Add code here for loading locations, working with them, etc.
219 }
220
221 // NavigationManager usage example
222 if (_navigationManager != null) {
223 print('NavigationManager ready for positioning');
224 // Add code here for getting position, setting up listeners, etc.
225 }
226
227 // ZoneManager usage example
228 if (_zoneManager != null) {
229 print('ZoneManager ready for zone operations');
230 // Add code here for setting up zones, handling enter/exit events, etc.
231 }
232
233 // RouteManager usage example
234 if (_routeManager != null) {
235 print('RouteManager ready for route building');
236 // Add code here for building routes, setting destination points, etc.
237 }
238
239 // AsyncRouteManager usage example
240 if (_asyncRouteManager != null) {
241 print('AsyncRouteManager ready for async route operations');
242 // Add code here for creating routing sessions, etc.
243 }
244
245 // NotificationManager usage example
246 if (_notificationManager != null) {
247 print('NotificationManager ready for notifications');
248 // Add code here for setting up beacon notifications, etc.
249 }
250
251 // MeasurementManager usage example
252 if (_measurementManager != null) {
253 print('MeasurementManager ready for measurements');
254 // Add code here for managing measurement generators, etc.
255 }
256
257 // LocationListManager usage example
258 if (_locationListManager != null) {
259 print('LocationListManager ready for location list operations');
260 // Add code here for getting available locations list, etc.
261 }
262
263 // StorageManager usage example
264 if (_storageManager != null) {
265 print('StorageManager ready for storage operations');
266 // Add code here for creating storages, managing data, etc.
267 }
268
269 // MqttSession usage example
270 if (_mqttSession != null) {
271 print('MqttSession ready for publishing position data via MQTT');
272 // Add code here for connecting to MQTT broker, publishing positions, etc.
273 }
274 }
275
280 print('=== Dart Features Demonstration ===');
281
282 // Using null-aware operators
283 _sdk?.setUserHash('YYYY-YYYY-YYYY-YYYY');
284 print('User hash updated');
285
286 // Using collection if for conditional element addition
287 final managers = <String>[
288 'LocationManager',
289 'NavigationManager',
290 if (_zoneManager != null) 'ZoneManager',
291 if (_routeManager != null) 'RouteManager',
292 if (_asyncRouteManager != null) 'AsyncRouteManager',
293 if (_notificationManager != null) 'NotificationManager',
294 if (_measurementManager != null) 'MeasurementManager',
295 if (_locationListManager != null) 'LocationListManager',
296 if (_storageManager != null) 'StorageManager',
297 if (_mqttSession != null) 'MqttSession',
298 ];
299 print('Available managers: $managers');
300
301 // Using map for data transformation
302 final sdkInfo = <String, String>{
303 'version': NavigineSdk.getVersion(),
304 'deviceId': NavigineSdk.getDeviceId(),
305 'relativeTime': NavigineSdk.getRelativeTime().toString(),
306 };
307
308 final infoStrings = sdkInfo.entries.map(
309 (entry) => '${entry.key}: ${entry.value}',
310 );
311 print('SDK information: ${infoStrings.join(', ')}');
312
313 // Using where for filtering
314 final allManagers = [
325 ];
326
327 final availableManagers =
328 allManagers.where((manager) => manager != null).length;
329 print('Available managers count: $availableManagers');
330 }
331
335 Future<void> demonstrateAsyncFeatures() async {
336 print('=== Async Features Demonstration ===');
337
338 // Simulating async operation
339 await Future.delayed(Duration(seconds: 1));
340 print('Async operation completed');
341
342 // Using async/await with error handling
343 try {
344 await _performAsyncOperation();
345 } catch (e) {
346 print('Error in async operation: $e');
347 }
348 }
349
353 Future<void> _performAsyncOperation() async {
354 await Future.delayed(Duration(milliseconds: 500));
355 print('Additional async operation completed');
356 }
357
362 print('=== Extension Methods Demonstration ===');
363
364 final status = _getManagersStatus();
365 print('Managers status: $status');
366
367 final isReady = _isSdkReady();
368 print('SDK ready for work: $isReady');
369 }
370
374 Future<void> runExample() async {
375 printSdkInfo();
378 await demonstrateAsyncFeatures();
381 }
382}
383
387extension NavigineSdkExampleExtension on NavigineSdkExample {
391 Map<String, bool> _getManagersStatus() {
392 return {
393 'LocationManager': _locationManager != null,
394 'NavigationManager': _navigationManager != null,
395 'ZoneManager': _zoneManager != null,
396 'RouteManager': _routeManager != null,
397 'AsyncRouteManager': _asyncRouteManager != null,
398 'NotificationManager': _notificationManager != null,
399 'MeasurementManager': _measurementManager != null,
400 'LocationListManager': _locationListManager != null,
401 'StorageManager': _storageManager != null,
402 'MqttSession': _mqttSession != null,
403 };
404 }
405
409 bool _isSdkReady() {
410 return _sdk != null && _locationManager != null;
411 }
412}
413
417class NavigineSdkFlutterExample {
418 static Future<void> initializeInFlutter() async {
419 print('=== Navigine SDK Initialization in Flutter ===');
420
421 final example = NavigineSdkExample();
422 await example.runExample();
423
424 print('Initialization completed');
425 }
426}
427
431void main() async {
432 final example = NavigineSdkExample();
433 await example.runExample();
434}