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
55 // [dart_NavigineSdk_getUserAgent]
56 print("User-Agent: ${NavigineSdk.getUserAgent()}");
57 // [dart_NavigineSdk_getUserAgent]
58
59 // [dart_NavigineSdk_reset]
60 _sdk!.reset();
61 print("SDK reset to initial state");
62 // [dart_NavigineSdk_reset]
63
64 // [dart_NavigineSdk_setServer]
65 // Set server URL (optional)
66 _sdk?.setServer('https://custom.navigine.com');
67 // [dart_NavigineSdk_setServer]
68
69 // Initialize managers
70 _initializeManagers();
71 } catch (e) {
72 print('SDK initialization error: $e');
73 }
74 }
75
79 void _initializeManagers() {
80 // [dart_NavigineSdk_getLocationManager]
81 // Get LocationManager for working with locations
82 _locationManager = _sdk?.getLocationManager();
83 if (_locationManager != null) {
84 print('LocationManager successfully initialized');
85 }
86 // [dart_NavigineSdk_getLocationManager]
87
88 // [dart_NavigineSdk_getNavigationManager]
89 // Get NavigationManager for navigation
90 if (_locationManager != null) {
91 _navigationManager = _sdk?.getNavigationManager(_locationManager!);
92 if (_navigationManager != null) {
93 print('NavigationManager successfully initialized');
94 }
95 }
96 // [dart_NavigineSdk_getNavigationManager]
97
98 // [dart_NavigineSdk_getZoneManager]
99 // Get ZoneManager for working with zones
100 if (_navigationManager != null) {
101 _zoneManager = _sdk?.getZoneManager(_navigationManager!);
102 if (_zoneManager != null) {
103 print('ZoneManager successfully initialized');
104 }
105 }
106 // [dart_NavigineSdk_getZoneManager]
107
108 // [dart_NavigineSdk_getRouteManager]
109 // Get RouteManager for building routes
110 if (_locationManager != null && _navigationManager != null) {
111 _routeManager = _sdk?.getRouteManager(
114 );
115 if (_routeManager != null) {
116 print('RouteManager successfully initialized');
117 }
118 }
119 // [dart_NavigineSdk_getRouteManager]
120
121 // [dart_NavigineSdk_getAsyncRouteManager]
122 // Get AsyncRouteManager for async route operations
123 if (_locationManager != null && _navigationManager != null) {
124 _asyncRouteManager = _sdk?.getAsyncRouteManager(
127 );
128 if (_asyncRouteManager != null) {
129 print('AsyncRouteManager successfully initialized');
130 }
131 }
132 // [dart_NavigineSdk_getAsyncRouteManager]
133
134 // [dart_NavigineSdk_getNotificationManager]
135 // Get NotificationManager for notifications
136 if (_locationManager != null) {
137 _notificationManager = _sdk?.getNotificationManager(_locationManager!);
138 if (_notificationManager != null) {
139 print('NotificationManager successfully initialized');
140 }
141 }
142 // [dart_NavigineSdk_getNotificationManager]
143
144 // [dart_NavigineSdk_getMeasurementManager]
145 // Get MeasurementManager for measurements
146 if (_locationManager != null) {
147 _measurementManager = _sdk?.getMeasurementManager(_locationManager!);
148 if (_measurementManager != null) {
149 print('MeasurementManager successfully initialized');
150 }
151 }
152 // [dart_NavigineSdk_getMeasurementManager]
153
154 // [dart_NavigineSdk_getLocationListManager]
155 // Get LocationListManager for location list operations
156 _locationListManager = _sdk?.getLocationListManager();
157 if (_locationListManager != null) {
158 print('LocationListManager successfully initialized');
159 }
160 // [dart_NavigineSdk_getLocationListManager]
161
162 // [dart_NavigineSdk_getStorageManager]
163 // Get StorageManager for working with storages
164 _storageManager = _sdk?.getStorageManager();
165 if (_storageManager != null) {
166 print('StorageManager successfully initialized');
167 }
168 // [dart_NavigineSdk_getStorageManager]
169
170 // [dart_NavigineSdk_getMqttSession]
171 // Get MqttSession for publishing position data via MQTT
172 if (_navigationManager != null) {
173 _mqttSession = _sdk?.getMqttSession(_navigationManager!);
174 if (_mqttSession != null) {
175 print('MqttSession successfully initialized');
176 }
177 }
178 // [dart_NavigineSdk_getMqttSession]
179 }
180
184 void printSdkInfo() {
185 print('=== Navigine SDK Information ===');
186 print('SDK Version: ${NavigineSdk.getVersion()}');
187 print('Device ID: ${NavigineSdk.getDeviceId()}');
188 print('Relative Time: ${NavigineSdk.getRelativeTime()}');
189 print(
190 'LocationManager: ${_locationManager != null ? "available" : "unavailable"}',
191 );
192 print(
193 'NavigationManager: ${_navigationManager != null ? "available" : "unavailable"}',
194 );
195 print('ZoneManager: ${_zoneManager != null ? "available" : "unavailable"}');
196 print(
197 'RouteManager: ${_routeManager != null ? "available" : "unavailable"}',
198 );
199 print(
200 'AsyncRouteManager: ${_asyncRouteManager != null ? "available" : "unavailable"}',
201 );
202 print(
203 'NotificationManager: ${_notificationManager != null ? "available" : "unavailable"}',
204 );
205 print(
206 'MeasurementManager: ${_measurementManager != null ? "available" : "unavailable"}',
207 );
208 print(
209 'LocationListManager: ${_locationListManager != null ? "available" : "unavailable"}',
210 );
211 print(
212 'StorageManager: ${_storageManager != null ? "available" : "unavailable"}',
213 );
214 print(
215 'MqttSession: ${_mqttSession != null ? "available" : "unavailable"}',
216 );
217 }
218
223 print('=== Manager Usage Demonstration ===');
224
225 // LocationManager usage example
226 if (_locationManager != null) {
227 print('LocationManager ready for location operations');
228 // Add code here for loading locations, working with them, etc.
229 }
230
231 // NavigationManager usage example
232 if (_navigationManager != null) {
233 print('NavigationManager ready for positioning');
234 // Add code here for getting position, setting up listeners, etc.
235 }
236
237 // ZoneManager usage example
238 if (_zoneManager != null) {
239 print('ZoneManager ready for zone operations');
240 // Add code here for setting up zones, handling enter/exit events, etc.
241 }
242
243 // RouteManager usage example
244 if (_routeManager != null) {
245 print('RouteManager ready for route building');
246 // Add code here for building routes, setting destination points, etc.
247 }
248
249 // AsyncRouteManager usage example
250 if (_asyncRouteManager != null) {
251 print('AsyncRouteManager ready for async route operations');
252 // Add code here for creating routing sessions, etc.
253 }
254
255 // NotificationManager usage example
256 if (_notificationManager != null) {
257 print('NotificationManager ready for notifications');
258 // Add code here for setting up beacon notifications, etc.
259 }
260
261 // MeasurementManager usage example
262 if (_measurementManager != null) {
263 print('MeasurementManager ready for measurements');
264 // Add code here for managing measurement generators, etc.
265 }
266
267 // LocationListManager usage example
268 if (_locationListManager != null) {
269 print('LocationListManager ready for location list operations');
270 // Add code here for getting available locations list, etc.
271 }
272
273 // StorageManager usage example
274 if (_storageManager != null) {
275 print('StorageManager ready for storage operations');
276 // Add code here for creating storages, managing data, etc.
277 }
278
279 // MqttSession usage example
280 if (_mqttSession != null) {
281 print('MqttSession ready for publishing position data via MQTT');
282 // Add code here for connecting to MQTT broker, publishing positions, etc.
283 }
284 }
285
290 print('=== Dart Features Demonstration ===');
291
292 // Using null-aware operators
293 _sdk?.setUserHash('YYYY-YYYY-YYYY-YYYY');
294 print('User hash updated');
295
296 // Using collection if for conditional element addition
297 final managers = <String>[
298 'LocationManager',
299 'NavigationManager',
300 if (_zoneManager != null) 'ZoneManager',
301 if (_routeManager != null) 'RouteManager',
302 if (_asyncRouteManager != null) 'AsyncRouteManager',
303 if (_notificationManager != null) 'NotificationManager',
304 if (_measurementManager != null) 'MeasurementManager',
305 if (_locationListManager != null) 'LocationListManager',
306 if (_storageManager != null) 'StorageManager',
307 if (_mqttSession != null) 'MqttSession',
308 ];
309 print('Available managers: $managers');
310
311 // Using map for data transformation
312 final sdkInfo = <String, String>{
313 'version': NavigineSdk.getVersion(),
314 'deviceId': NavigineSdk.getDeviceId(),
315 'relativeTime': NavigineSdk.getRelativeTime().toString(),
316 };
317
318 final infoStrings = sdkInfo.entries.map(
319 (entry) => '${entry.key}: ${entry.value}',
320 );
321 print('SDK information: ${infoStrings.join(', ')}');
322
323 // Using where for filtering
324 final allManagers = [
335 ];
336
337 final availableManagers =
338 allManagers.where((manager) => manager != null).length;
339 print('Available managers count: $availableManagers');
340 }
341
345 Future<void> demonstrateAsyncFeatures() async {
346 print('=== Async Features Demonstration ===');
347
348 // Simulating async operation
349 await Future.delayed(Duration(seconds: 1));
350 print('Async operation completed');
351
352 // Using async/await with error handling
353 try {
354 await _performAsyncOperation();
355 } catch (e) {
356 print('Error in async operation: $e');
357 }
358 }
359
363 Future<void> _performAsyncOperation() async {
364 await Future.delayed(Duration(milliseconds: 500));
365 print('Additional async operation completed');
366 }
367
372 print('=== Extension Methods Demonstration ===');
373
374 final status = _getManagersStatus();
375 print('Managers status: $status');
376
377 final isReady = _isSdkReady();
378 print('SDK ready for work: $isReady');
379 }
380
384 Future<void> runExample() async {
385 printSdkInfo();
388 await demonstrateAsyncFeatures();
391 }
392}
393
397extension NavigineSdkExampleExtension on NavigineSdkExample {
401 Map<String, bool> _getManagersStatus() {
402 return {
403 'LocationManager': _locationManager != null,
404 'NavigationManager': _navigationManager != null,
405 'ZoneManager': _zoneManager != null,
406 'RouteManager': _routeManager != null,
407 'AsyncRouteManager': _asyncRouteManager != null,
408 'NotificationManager': _notificationManager != null,
409 'MeasurementManager': _measurementManager != null,
410 'LocationListManager': _locationListManager != null,
411 'StorageManager': _storageManager != null,
412 'MqttSession': _mqttSession != null,
413 };
414 }
415
419 bool _isSdkReady() {
420 return _sdk != null && _locationManager != null;
421 }
422}
423
427class NavigineSdkFlutterExample {
428 static Future<void> initializeInFlutter() async {
429 print('=== Navigine SDK Initialization in Flutter ===');
430
431 final example = NavigineSdkExample();
432 await example.runExample();
433
434 print('Initialization completed');
435 }
436}
437
441void main() async {
442 final example = NavigineSdkExample();
443 await example.runExample();
444}