9class StorageManagerExample {
16 StorageManagerExample() {
24 void _initializeSdk() {
47 print(
"StorageManager successfully initialized");
50 print(
"Error initializing SDK: $e");
57 void _setupStorages() {
59 print(
"StorageManager not initialized");
70 print(
"Storage instances created");
78 print(
"StorageManager not initialized");
85 print(
"Existing storages: $storageList");
90 KeyValueStorage testStorage =
_storageManager!.getStorage(
"test_storage");
91 print(
"Created test storage");
97 print(
"Updated storage list: $updatedList");
102 print(
"Removed test storage");
106 print(
"Final storage list: $finalList");
114 print(
"User storage not initialized");
118 print(
"\n=== KeyValueStorage Methods Demonstration ===");
123 _userStorage!.putString(
"user_email",
"john.doe@example.com");
124 print(
"Stored string values");
131 print(
"Stored integer values");
136 _userStorage!.putLong(
"registration_timestamp", 1640995200000);
138 "last_login_timestamp",
139 DateTime.now().millisecondsSinceEpoch,
141 print(
"Stored long values");
148 print(
"Stored boolean values");
155 print(
"Stored float values");
162 print(
"Stored double values");
168 bool hasNonExistent =
_userStorage!.contains(
"non_existent_key");
169 print(
"Contains 'user_name': $hasUserName");
170 print(
"Contains 'non_existent_key': $hasNonExistent");
176 print(
"All stored keys: $allKeys");
181 String userName =
_userStorage!.getString(
"user_name",
"Unknown");
182 String userEmail =
_userStorage!.getString(
"user_email",
"");
187 print(
"User name: $userName");
188 print(
"User email: $userEmail");
189 print(
"Non-existent key: $nonExistent");
195 int loginCount =
_userStorage!.getInt(
"login_count", 0);
196 int nonExistentInt =
_userStorage!.getInt(
"non_existent_int", -1);
197 print(
"User age: $userAge");
198 print(
"Login count: $loginCount");
199 print(
"Non-existent int: $nonExistentInt");
204 long regTimestamp =
_userStorage!.getLong(
"registration_timestamp", 0);
205 long lastLogin =
_userStorage!.getLong(
"last_login_timestamp", 0);
206 long nonExistentLong =
_userStorage!.getLong(
"non_existent_long", -1);
207 print(
"Registration timestamp: $regTimestamp");
208 print(
"Last login timestamp: $lastLogin");
209 print(
"Non-existent long: $nonExistentLong");
214 bool isPremium =
_userStorage!.getBool(
"is_premium",
false);
216 "notifications_enabled",
219 bool nonExistentBool =
_userStorage!.getBool(
"non_existent_bool",
false);
220 print(
"Is premium: $isPremium");
221 print(
"Notifications enabled: $notificationsEnabled");
222 print(
"Non-existent bool: $nonExistentBool");
227 float userRating =
_userStorage!.getFloat(
"user_rating", 0.0);
228 float temperature =
_userStorage!.getFloat(
"temperature", 0.0);
229 float nonExistentFloat =
_userStorage!.getFloat(
"non_existent_float", -1.0);
230 print(
"User rating: $userRating");
231 print(
"Temperature: $temperature");
232 print(
"Non-existent float: $nonExistentFloat");
237 double userLat =
_userStorage!.getDouble(
"user_location_lat", 0.0);
238 double userLng =
_userStorage!.getDouble(
"user_location_lng", 0.0);
240 "non_existent_double",
243 print(
"User location lat: $userLat");
244 print(
"User location lng: $userLng");
245 print(
"Non-existent double: $nonExistentDouble");
252 print(
"Removed 'user_age' key");
257 print(
"Still contains 'user_age': $stillHasAge");
262 print(
"Cleared all data from user storage");
267 print(
"Keys after clear: $keysAfterClear");
275 print(
"Storages not initialized");
279 print(
"\n=== Multiple Storages Demonstration ===");
292 DateTime.now().millisecondsSinceEpoch,
298 print(
"User storage data:");
301 print(
"\nApp storage data:");
304 print(
"\nCache storage data:");
311 void _demonstrateStorageData(KeyValueStorage storage) {
312 List<String> keys = storage.
getKeys();
313 for (String key in keys) {
316 String stringValue = storage.
getString(key,
"");
317 if (stringValue.isNotEmpty) {
318 print(
" $key: $stringValue (string)");
323 int intValue = storage.
getInt(key, -999999);
324 if (intValue != -999999) {
325 print(
" $key: $intValue (int)");
330 long longValue = storage.
getLong(key, -999999);
331 if (longValue != -999999) {
332 print(
" $key: $longValue (long)");
337 bool boolValue = storage.
getBool(key,
false);
339 print(
" $key: $boolValue (bool)");
344 float floatValue = storage.
getFloat(key, -999999.0);
345 if (floatValue != -999999.0) {
346 print(
" $key: $floatValue (float)");
351 double doubleValue = storage.
getDouble(key, -999999.0);
352 if (doubleValue != -999999.0) {
353 print(
" $key: $doubleValue (double)");
364 print(
"StorageManager not initialized");
368 print(
"\n=== Storage Analytics ===");
372 print(
"Total storages: ${allStorages.length}");
374 for (String storageName in allStorages) {
376 List<String> keys = storage.
getKeys();
377 print(
"Storage '$storageName' contains ${keys.length} items");
387 for (String key in keys) {
389 String stringValue = storage.
getString(key,
"");
390 if (stringValue.isNotEmpty) {
395 int intValue = storage.
getInt(key, -999999);
396 if (intValue != -999999) {
401 long longValue = storage.
getLong(key, -999999);
402 if (longValue != -999999) {
407 bool boolValue = storage.
getBool(key,
false);
413 float floatValue = storage.
getFloat(key, -999999.0);
414 if (floatValue != -999999.0) {
419 double doubleValue = storage.
getDouble(key, -999999.0);
420 if (doubleValue != -999999.0) {
425 print(
" - Strings: $stringCount");
426 print(
" - Integers: $intCount");
427 print(
" - Longs: $longCount");
428 print(
" - Booleans: $boolCount");
429 print(
" - Floats: $floatCount");
430 print(
" - Doubles: $doubleCount");
439 print(
"StorageManager not initialized");
443 print(
"\n=== Data Migration Demonstration ===");
446 KeyValueStorage oldStorage =
_storageManager!.getStorage(
"old_storage");
447 KeyValueStorage newStorage =
_storageManager!.getStorage(
"new_storage");
450 oldStorage.
putString(
"name",
"John Doe");
451 oldStorage.
putInt(
"age", 25);
452 oldStorage.
putBool(
"is_premium",
true);
455 print(
"Old storage before migration:");
456 _demonstrateStorageData(oldStorage);
459 List<String> keys = oldStorage.
getKeys();
460 for (String key in keys) {
462 String stringValue = oldStorage.
getString(key,
"");
463 if (stringValue.isNotEmpty) {
469 int intValue = oldStorage.
getInt(key, -999999);
470 if (intValue != -999999) {
471 newStorage.
putInt(key, intValue);
476 long longValue = oldStorage.
getLong(key, -999999);
477 if (longValue != -999999) {
478 newStorage.
putLong(key, longValue);
483 bool boolValue = oldStorage.
getBool(key,
false);
485 newStorage.
putBool(key, boolValue);
490 float floatValue = oldStorage.
getFloat(key, -999999.0);
491 if (floatValue != -999999.0) {
492 newStorage.
putFloat(key, floatValue);
497 double doubleValue = oldStorage.
getDouble(key, -999999.0);
498 if (doubleValue != -999999.0) {
503 print(
"\nNew storage after migration:");
504 _demonstrateStorageData(newStorage);
508 print(
"\nRemoved old storage");
512 print(
"Final storage list: $finalStorages");
520 print(
"StorageManager not initialized");
524 print(
"\n=== Storage Cleanup Demonstration ===");
532 print(
"Storages before cleanup: $beforeCleanup");
536 for (String storageName in storages) {
537 if (storageName.startsWith(
"temp_")) {
539 print(
"Removed temporary storage: $storageName");
544 print(
"Storages after cleanup: $afterCleanup");
551 print(
"=== StorageManager and KeyValueStorage Examples ===\n");
560 print(
"\n=== All demonstrations completed ===");
570 for (String storageName in storages) {
571 if (storageName.startsWith(
"test_") ||
572 storageName.startsWith(
"temp_") ||
573 storageName.startsWith(
"old_") ||
574 storageName.startsWith(
"new_")) {