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 {
22
23 NavigineSdkExample() {
24 _initializeSdk();
25 }
26
30 void _initializeSdk() {
31 try {
32 // [dart_NavigineSdk_getInstance]
33 // Get SDK instance
35 // [dart_NavigineSdk_getInstance]
36
37 // [dart_NavigineSdk_getVersion]
38 // Get SDK version
39 print('Navigine SDK Version: ${NavigineSdk.getVersion()}');
40 // [dart_NavigineSdk_getVersion]
41
42 // [dart_NavigineSdk_getDeviceId]
43 // Get device ID
44 print('Device ID: ${NavigineSdk.getDeviceId()}');
45 // [dart_NavigineSdk_getDeviceId]
46
47 // [dart_NavigineSdk_getRelativeTime]
48 // Get relative time
49 print('Relative Time: ${NavigineSdk.getRelativeTime()}');
50 // [dart_NavigineSdk_getRelativeTime]
51
52 // [dart_NavigineSdk_setUserHash]
53 // Set user hash (authorization token)
54 _sdk?.setUserHash('XXXX-XXXX-XXXX-XXXX');
55 // [dart_NavigineSdk_setUserHash]
56
57
58 // [dart_NavigineSdk_getUserAgent]
59 print("User-Agent: ${NavigineSdk.getUserAgent()}");
60 // [dart_NavigineSdk_getUserAgent]
61
62 // [dart_NavigineSdk_reset]
63 _sdk!.reset();
64 print("SDK reset to initial state");
65 // [dart_NavigineSdk_reset]
66
67 // [dart_NavigineSdk_setServer]
68 // Set server URL (optional)
69 _sdk?.setServer('https://custom.navigine.com');
70 // [dart_NavigineSdk_setServer]
71
72 // Initialize managers
73 _initializeManagers();
74 } catch (e) {
75 print('SDK initialization error: $e');
76 }
77 }
78
82 void _initializeManagers() {
83 // [dart_NavigineSdk_getLocationManager]
84 // Get LocationManager for working with locations
85 _locationManager = _sdk?.getLocationManager();
86 if (_locationManager != null) {
87 print('LocationManager successfully initialized');
88 }
89 // [dart_NavigineSdk_getLocationManager]
90
91 // [dart_NavigineSdk_getNavigationManager]
92 // Get NavigationManager for navigation
93 if (_locationManager != null) {
94 _navigationManager = _sdk?.getNavigationManager(_locationManager!);
95 if (_navigationManager != null) {
96 print('NavigationManager successfully initialized');
97 }
98 }
99 // [dart_NavigineSdk_getNavigationManager]
100
101 // [dart_NavigineSdk_getZoneManager]
102 // Get ZoneManager for working with zones
103 if (_navigationManager != null) {
104 _zoneManager = _sdk?.getZoneManager(_navigationManager!);
105 if (_zoneManager != null) {
106 print('ZoneManager successfully initialized');
107 }
108 }
109 // [dart_NavigineSdk_getZoneManager]
110
111 // [dart_NavigineSdk_getRouteManager]
112 // Get RouteManager for building routes
113 if (_locationManager != null && _navigationManager != null) {
114 _routeManager = _sdk?.getRouteManager(
117 );
118 if (_routeManager != null) {
119 print('RouteManager successfully initialized');
120 }
121 }
122 // [dart_NavigineSdk_getRouteManager]
123
124 // [dart_NavigineSdk_getAsyncRouteManager]
125 // Get AsyncRouteManager for async route operations
126 if (_locationManager != null && _navigationManager != null) {
127 _asyncRouteManager = _sdk?.getAsyncRouteManager(
130 );
131 if (_asyncRouteManager != null) {
132 print('AsyncRouteManager successfully initialized');
133 }
134 }
135 // [dart_NavigineSdk_getAsyncRouteManager]
136
137 // [dart_NavigineSdk_getNotificationManager]
138 // Get NotificationManager for notifications
139 if (_locationManager != null) {
140 _notificationManager = _sdk?.getNotificationManager(_locationManager!);
141 if (_notificationManager != null) {
142 print('NotificationManager successfully initialized');
143 }
144 }
145 // [dart_NavigineSdk_getNotificationManager]
146
147 // [dart_NavigineSdk_getMeasurementManager]
148 // Get MeasurementManager for measurements
149 if (_locationManager != null) {
150 _measurementManager = _sdk?.getMeasurementManager(_locationManager!);
151 if (_measurementManager != null) {
152 print('MeasurementManager successfully initialized');
153 }
154 }
155 // [dart_NavigineSdk_getMeasurementManager]
156
157 // [dart_NavigineSdk_getLocationListManager]
158 // Get LocationListManager for location list operations
159 _locationListManager = _sdk?.getLocationListManager();
160 if (_locationListManager != null) {
161 print('LocationListManager successfully initialized');
162 }
163 // [dart_NavigineSdk_getLocationListManager]
164
165 // [dart_NavigineSdk_getStorageManager]
166 // Get StorageManager for working with storages
167 _storageManager = _sdk?.getStorageManager();
168 if (_storageManager != null) {
169 print('StorageManager successfully initialized');
170 }
171 // [dart_NavigineSdk_getStorageManager]
172
173 // [dart_NavigineSdk_getRouteLayer]
174 // Create RouteLayer for building and drawing routes on the map
176 if (locationWindow != null) {
177 _routeLayer = _sdk?.getRouteLayer(locationWindow);
178 if (_routeLayer != null) {
179 print('RouteLayer successfully initialized');
180 }
181 }
182 // [dart_NavigineSdk_getRouteLayer]
183
184 // [dart_NavigineSdk_getGuidanceCamera]
185 final routeLayer = _routeLayer;
186 if (locationWindow != null && routeLayer != null) {
187 _guidanceCamera = _sdk?.getGuidanceCamera(locationWindow, routeLayer);
188 // [dart_GuidanceCamera_setMode]
189 _guidanceCamera?.setMode(GuidanceCameraMode.FOLLOWING);
190 // [dart_GuidanceCamera_setMode]
191 // [dart_GuidanceCamera_set2DMode]
192 _guidanceCamera?.set2DMode(false);
193 // [dart_GuidanceCamera_set2DMode]
194 // [dart_GuidanceCamera_mode]
195 print('Guidance mode: ${_guidanceCamera?.mode()}');
196 // [dart_GuidanceCamera_mode]
197 // [dart_GuidanceCamera_instruction]
198 final next = _guidanceCamera?.instruction();
199 print('Next instruction: ${next?.title} ${next?.distance} m');
200 // [dart_GuidanceCamera_instruction]
201 }
202 // [dart_NavigineSdk_getGuidanceCamera]
203
204 // [dart_NavigineSdk_getRouteSimulator]
205 if (locationWindow != null) {
206 final routeSimulator = _sdk?.getRouteSimulator(locationWindow);
207 // [dart_RouteSimulator_setGeometry]
208 final walk = LocationPolyline(
209 [GlobalPoint(55.751, 37.618), GlobalPoint(55.752, 37.618)],
210 null,
211 );
212 routeSimulator?.setGeometry([walk]);
213 // [dart_RouteSimulator_setGeometry]
214 // [dart_RouteSimulator_setSpeed]
215 routeSimulator?.setSpeed(1.4);
216 // [dart_RouteSimulator_setSpeed]
217 // [dart_RouteSimulator_start]
218 final started = routeSimulator?.start() ?? false;
219 print('Route walk started: $started');
220 // [dart_RouteSimulator_start]
221 // [dart_RouteSimulator_sample]
222 final sample = routeSimulator?.sample();
223 print('Walk advance: ${sample?.advance} m');
224 // [dart_RouteSimulator_sample]
225 }
226 // [dart_NavigineSdk_getRouteSimulator]
227
228 // [dart_NavigineSdk_getMqttSession]
229 // Get MqttSession for publishing position data via MQTT
230 if (_navigationManager != null) {
231 _mqttSession = _sdk?.getMqttSession(_navigationManager!);
232 if (_mqttSession != null) {
233 print('MqttSession successfully initialized');
234 }
235 }
236 // [dart_NavigineSdk_getMqttSession]
237 }
238
242 void printSdkInfo() {
243 print('=== Navigine SDK Information ===');
244 print('SDK Version: ${NavigineSdk.getVersion()}');
245 print('Device ID: ${NavigineSdk.getDeviceId()}');
246 print('Relative Time: ${NavigineSdk.getRelativeTime()}');
247 print(
248 'LocationManager: ${_locationManager != null ? "available" : "unavailable"}',
249 );
250 print(
251 'NavigationManager: ${_navigationManager != null ? "available" : "unavailable"}',
252 );
253 print('ZoneManager: ${_zoneManager != null ? "available" : "unavailable"}');
254 print(
255 'RouteManager: ${_routeManager != null ? "available" : "unavailable"}',
256 );
257 print(
258 'AsyncRouteManager: ${_asyncRouteManager != null ? "available" : "unavailable"}',
259 );
260 print(
261 'NotificationManager: ${_notificationManager != null ? "available" : "unavailable"}',
262 );
263 print(
264 'MeasurementManager: ${_measurementManager != null ? "available" : "unavailable"}',
265 );
266 print(
267 'LocationListManager: ${_locationListManager != null ? "available" : "unavailable"}',
268 );
269 print(
270 'StorageManager: ${_storageManager != null ? "available" : "unavailable"}',
271 );
272 print(
273 'MqttSession: ${_mqttSession != null ? "available" : "unavailable"}',
274 );
275 }
276
281 print('=== Manager Usage Demonstration ===');
282
283 // LocationManager usage example
284 if (_locationManager != null) {
285 print('LocationManager ready for location operations');
286 // Add code here for loading locations, working with them, etc.
287 }
288
289 // NavigationManager usage example
290 if (_navigationManager != null) {
291 print('NavigationManager ready for positioning');
292 // Add code here for getting position, setting up listeners, etc.
293 }
294
295 // ZoneManager usage example
296 if (_zoneManager != null) {
297 print('ZoneManager ready for zone operations');
298 // Add code here for setting up zones, handling enter/exit events, etc.
299 }
300
301 // RouteManager usage example
302 if (_routeManager != null) {
303 print('RouteManager ready for route building');
304 // Add code here for building routes, setting destination points, etc.
305 }
306
307 // AsyncRouteManager usage example
308 if (_asyncRouteManager != null) {
309 print('AsyncRouteManager ready for async route operations');
310 // Add code here for creating routing sessions, etc.
311 }
312
313 // NotificationManager usage example
314 if (_notificationManager != null) {
315 print('NotificationManager ready for notifications');
316 // Add code here for setting up beacon notifications, etc.
317 }
318
319 // MeasurementManager usage example
320 if (_measurementManager != null) {
321 print('MeasurementManager ready for measurements');
322 // Add code here for managing measurement generators, etc.
323 }
324
325 // LocationListManager usage example
326 if (_locationListManager != null) {
327 print('LocationListManager ready for location list operations');
328 // Add code here for getting available locations list, etc.
329 }
330
331 // StorageManager usage example
332 if (_storageManager != null) {
333 print('StorageManager ready for storage operations');
334 // Add code here for creating storages, managing data, etc.
335 }
336
337 // MqttSession usage example
338 if (_mqttSession != null) {
339 print('MqttSession ready for publishing position data via MQTT');
340 // Add code here for connecting to MQTT broker, publishing positions, etc.
341 }
342 }
343
348 print('=== Dart Features Demonstration ===');
349
350 // Using null-aware operators
351 _sdk?.setUserHash('YYYY-YYYY-YYYY-YYYY');
352 print('User hash updated');
353
354 // Using collection if for conditional element addition
355 final managers = <String>[
356 'LocationManager',
357 'NavigationManager',
358 if (_zoneManager != null) 'ZoneManager',
359 if (_routeManager != null) 'RouteManager',
360 if (_asyncRouteManager != null) 'AsyncRouteManager',
361 if (_notificationManager != null) 'NotificationManager',
362 if (_measurementManager != null) 'MeasurementManager',
363 if (_locationListManager != null) 'LocationListManager',
364 if (_storageManager != null) 'StorageManager',
365 if (_mqttSession != null) 'MqttSession',
366 ];
367 print('Available managers: $managers');
368
369 // Using map for data transformation
370 final sdkInfo = <String, String>{
371 'version': NavigineSdk.getVersion(),
372 'deviceId': NavigineSdk.getDeviceId(),
373 'relativeTime': NavigineSdk.getRelativeTime().toString(),
374 };
375
376 final infoStrings = sdkInfo.entries.map(
377 (entry) => '${entry.key}: ${entry.value}',
378 );
379 print('SDK information: ${infoStrings.join(', ')}');
380
381 // Using where for filtering
382 final allManagers = [
393 ];
394
395 final availableManagers =
396 allManagers.where((manager) => manager != null).length;
397 print('Available managers count: $availableManagers');
398 }
399
403 Future<void> demonstrateAsyncFeatures() async {
404 print('=== Async Features Demonstration ===');
405
406 // Simulating async operation
407 await Future.delayed(Duration(seconds: 1));
408 print('Async operation completed');
409
410 // Using async/await with error handling
411 try {
412 await _performAsyncOperation();
413 } catch (e) {
414 print('Error in async operation: $e');
415 }
416 }
417
421 Future<void> _performAsyncOperation() async {
422 await Future.delayed(Duration(milliseconds: 500));
423 print('Additional async operation completed');
424 }
425
430 print('=== Extension Methods Demonstration ===');
431
432 final status = _getManagersStatus();
433 print('Managers status: $status');
434
435 final isReady = _isSdkReady();
436 print('SDK ready for work: $isReady');
437 }
438
442 Future<void> runExample() async {
443 printSdkInfo();
446 await demonstrateAsyncFeatures();
449 }
450}
451
455extension NavigineSdkExampleExtension on NavigineSdkExample {
459 Map<String, bool> _getManagersStatus() {
460 return {
461 'LocationManager': _locationManager != null,
462 'NavigationManager': _navigationManager != null,
463 'ZoneManager': _zoneManager != null,
464 'RouteManager': _routeManager != null,
465 'AsyncRouteManager': _asyncRouteManager != null,
466 'NotificationManager': _notificationManager != null,
467 'MeasurementManager': _measurementManager != null,
468 'LocationListManager': _locationListManager != null,
469 'StorageManager': _storageManager != null,
470 'MqttSession': _mqttSession != null,
471 };
472 }
473
477 bool _isSdkReady() {
478 return _sdk != null && _locationManager != null;
479 }
480}
481
485class NavigineSdkFlutterExample {
486 static Future<void> initializeInFlutter() async {
487 print('=== Navigine SDK Initialization in Flutter ===');
488
489 final example = NavigineSdkExample();
490 await example.runExample();
491
492 print('Initialization completed');
493 }
494}
495
499void main() async {
500 final example = NavigineSdkExample();
501 await example.runExample();
502}