9class LocationListManagerExample {
11 LocationListManager? _locationListManager;
12 LocationListListener? _locationListListener;
14 LocationListManagerExample() {
16 _setupLocationListListener();
22 void _initializeSdk() {
26 _sdk = NavigineSdk.getInstance();
31 _sdk?.setUserHash(
"USER-HASH-HERE");
36 _sdk?.setServer(
"https://custom.navigine.com");
41 _locationListManager = _sdk?.getLocationListManager();
44 if (_locationListManager !=
null) {
45 print(
"LocationListManager successfully initialized");
48 print(
"Error initializing SDK: $e");
55 void _setupLocationListListener() {
56 _locationListListener = LocationListListener(
58 onLocationListLoaded: (Map<int, LocationInfo> locationInfos) {
59 print(
"Location list loaded");
60 _demonstrateLocationList(locationInfos);
65 onLocationListFailed: (Error error) {
66 print(
"Location list failed: ${error.message}");
67 _demonstrateErrorHandling(error);
76 void demonstrateLocationListManagerMethods() {
77 if (_locationListManager ==
null) {
78 print(
"LocationListManager not initialized");
84 _locationListManager!.addLocationListListener(_locationListListener!);
85 print(
"Added location list listener");
90 _locationListManager!.updateLocationList();
91 print(
"Requested location list update");
96 Map<int, LocationInfo> currentLocationList = _locationListManager!.getLocationList();
97 print(
"Current location list contains ${currentLocationList.length} locations");
98 _demonstrateLocationList(currentLocationList);
102 Future.delayed(Duration(seconds: 2), () {
105 _locationListManager!.removeLocationListListener(_locationListListener!);
106 print(
"Removed location list listener");
114 void _demonstrateLocationList(Map<int, LocationInfo> locationInfos) {
115 if (locationInfos.isEmpty) {
116 print(
"Location list is empty");
120 print(
"=== Location List ===");
121 locationInfos.forEach((locationId, locationInfo) {
122 _demonstrateLocationInfo(locationInfo);
124 print(
"====================");
130 void _demonstrateLocationInfo(LocationInfo locationInfo) {
133 int id = locationInfo.id;
134 print(
"Location ID: $id");
139 int version = locationInfo.version;
140 print(
"Location version: $version");
145 String name = locationInfo.name;
146 print(
"Location name: $name");
155 void _demonstrateErrorHandling(Error error) {
156 print(
"Handling location list error:");
157 print(
" Error message: ${error.message}");
158 print(
" Error type: ${error.runtimeType}");
164 Future<void> demonstrateAdvancedLocationListFeatures() async {
165 print(
"=== Advanced Location List Features ===");
167 if (_locationListManager ==
null) {
172 LocationListListener listener1 = LocationListListener(
173 onLocationListLoaded: (Map<int, LocationInfo> locationInfos) {
174 print(
"Listener 1: Location list loaded - ${locationInfos.length} locations");
176 onLocationListFailed: (Error error) {
177 print(
"Listener 1: Location list failed - ${error.message}");
181 LocationListListener listener2 = LocationListListener(
182 onLocationListLoaded: (Map<int, LocationInfo> locationInfos) {
183 print(
"Listener 2: Location list loaded - ${locationInfos.length} locations");
185 onLocationListFailed: (Error error) {
186 print(
"Listener 2: Location list failed - ${error.message}");
192 _locationListManager!.addLocationListListener(listener1);
193 print(
"Added first location list listener");
196 await Future.delayed(Duration(seconds: 1));
200 _locationListManager!.addLocationListListener(listener2);
201 print(
"Added second location list listener");
205 _locationListManager!.updateLocationList();
208 await Future.delayed(Duration(seconds: 3));
213 _locationListManager!.removeLocationListListener(listener1);
214 print(
"Removed first location list listener");
217 await Future.delayed(Duration(seconds: 1));
221 _locationListManager!.removeLocationListListener(listener2);
222 print(
"Removed second location list listener");
229 void demonstrateLocationListSimulation() {
230 print(
"=== Location List Simulation ===");
233 Map<int, LocationInfo> simulatedLocations = {
234 1001: LocationInfo(1001, 1,
"Shopping Mall"),
235 1002: LocationInfo(1002, 2,
"Office Building"),
236 1003: LocationInfo(1003, 1,
"Airport Terminal"),
237 1004: LocationInfo(1004, 3,
"University Campus"),
241 Future.delayed(Duration(seconds: 1), () {
242 print(
"Simulated location list loaded");
243 _demonstrateLocationList(simulatedLocations);
247 Future.delayed(Duration(seconds: 3), () {
248 Map<int, LocationInfo> updatedLocations = {
249 1001: LocationInfo(1001, 2,
"Shopping Mall - Updated"),
250 1002: LocationInfo(1002, 3,
"Office Building - Updated"),
251 1003: LocationInfo(1003, 2,
"Airport Terminal - Updated"),
252 1004: LocationInfo(1004, 4,
"University Campus - Updated"),
253 1005: LocationInfo(1005, 1,
"New Hospital"),
255 print(
"Simulated location list updated");
256 _demonstrateLocationList(updatedLocations);
263 void demonstrateLocationListListenerManagement() {
264 print(
"=== Location List Listener Management ===");
266 if (_locationListManager ==
null) {
271 LocationListListener testListener = LocationListListener(
272 onLocationListLoaded: (Map<int, LocationInfo> locationInfos) {
273 print(
"Test listener received location list: ${locationInfos.length} locations");
275 onLocationListFailed: (Error error) {
276 print(
"Test listener received error: ${error.message}");
281 _locationListManager!.addLocationListListener(testListener);
282 print(
"Added test location list listener");
285 _locationListManager!.updateLocationList();
288 Future.delayed(Duration(seconds: 2), () {
290 _locationListManager!.removeLocationListListener(testListener);
291 print(
"Removed test location list listener");
298 Future<void> runExample() async {
299 print(
"=== LocationListManager Example ===");
301 demonstrateLocationListManagerMethods();
302 demonstrateLocationListListenerManagement();
303 await demonstrateAdvancedLocationListFeatures();
304 demonstrateLocationListSimulation();
307 await Future.delayed(Duration(seconds: 5));
309 print(
"=== Example completed ===");