{
  "id": "flutter/shared-preferences-corruption",
  "signature": "FormatException: Invalid radix-10 number (at character 1) while reading SharedPreferences",
  "signature_zh": "FormatException：读取 SharedPreferences 时出现无效的十进制数字（字符 1）",
  "regex": "FormatException: Invalid radix-10 number \\(at character 1\\) while reading SharedPreferences",
  "domain": "flutter",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "A value stored in SharedPreferences (or NSUserDefaults) was expected to be an integer but was corrupted or saved as a non-numeric string, often due to version mismatches or manual editing.",
  "root_cause_type": "generic",
  "root_cause_zh": "SharedPreferences（或 NSUserDefaults）中存储的值应为整数，但已损坏或保存为非数字字符串，通常是由于版本不匹配或手动编辑所致。",
  "versions": [
    {
      "version": "Flutter 3.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Dart 3.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android 13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "iOS 16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This deletes all user preferences, causing loss of user settings and potentially breaking app functionality; it's a nuclear option that should only be used as a last resort.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The corruption remains in storage and will cause the same error on every app restart; the default value may not match user expectations.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Not feasible for production apps; root access is rare and editing XML can cause further corruption or crash the app.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a migration function that reads the corrupted value as a string, attempts to parse it, and if it fails, removes the key and sets a default. Example: `final raw = prefs.getString('counter'); int? value; try { value = int.parse(raw!); } catch (e) { await prefs.remove('counter'); value = 0; }`",
      "success_rate": 0.85,
      "how": "Use a migration function that reads the corrupted value as a string, attempts to parse it, and if it fails, removes the key and sets a default. Example: `final raw = prefs.getString('counter'); int? value; try { value = int.parse(raw!); } catch (e) { await prefs.remove('counter'); value = 0; }`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a versioned SharedPreferences wrapper that validates data types on read and repairs corrupted entries automatically.",
      "success_rate": 0.75,
      "how": "Implement a versioned SharedPreferences wrapper that validates data types on read and repairs corrupted entries automatically.",
      "condition": "",
      "sources": []
    },
    {
      "action": "For critical data, migrate to a more robust storage solution like Hive or Isar that includes type safety and corruption detection.",
      "success_rate": 0.8,
      "how": "For critical data, migrate to a more robust storage solution like Hive or Isar that includes type safety and corruption detection.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use a migration function that reads the corrupted value as a string, attempts to parse it, and if it fails, removes the key and sets a default. Example: `final raw = prefs.getString('counter'); int? value; try { value = int.parse(raw!); } catch (e) { await prefs.remove('counter'); value = 0; }`",
    "Implement a versioned SharedPreferences wrapper that validates data types on read and repairs corrupted entries automatically.",
    "For critical data, migrate to a more robust storage solution like Hive or Isar that includes type safety and corruption detection."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://api.flutter.dev/flutter/package-shared_preferences-shared_preferences/SharedPreferences-class.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2024-04-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}