{
  "id": "flutter/setstate-after-dispose",
  "signature": "setState() called after dispose(): _MyWidgetState#abcde(lifecycle state: defunct, not mounted)",
  "signature_zh": "setState() 在 dispose() 后调用：_MyWidgetState#abcde（生命周期状态：已失效，未挂载）",
  "regex": "setState\\(\\) called after dispose\\(\\): \\S+#\\w+\\(lifecycle state: defunct, not mounted\\)",
  "domain": "flutter",
  "category": "lifecycle_error",
  "subcategory": null,
  "root_cause": "A stateful widget's setState() is invoked after the widget has been removed from the tree and disposed, often due to an asynchronous callback completing after disposal.",
  "root_cause_type": "generic",
  "root_cause_zh": "有状态小部件的 setState() 在小部件已从树中移除并释放后被调用，通常是由于异步回调在释放后完成。",
  "versions": [
    {
      "version": "Flutter 3.16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Dart 3.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android SDK 33",
      "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": "Calling setState() in a try-catch block and ignoring the error",
      "why_fails": "Does not prevent the call; the error still occurs and may cause undefined behavior.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrapping setState() in a timeout to delay execution",
      "why_fails": "Delay does not guarantee the widget is still mounted; race condition remains.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a global flag to skip setState() without checking mounted",
      "why_fails": "Global flags are error-prone and may miss widget-specific lifecycle states.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check the 'mounted' property before calling setState() in asynchronous code.",
      "success_rate": 0.95,
      "how": "Check the 'mounted' property before calling setState() in asynchronous code.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Cancel subscriptions or futures in the dispose() method to prevent callbacks from firing.",
      "success_rate": 0.85,
      "how": "Cancel subscriptions or futures in the dispose() method to prevent callbacks from firing.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a StatefulWidget with AutomaticKeepAliveClientMixin if the widget should persist across navigation.",
      "success_rate": 0.7,
      "how": "Use a StatefulWidget with AutomaticKeepAliveClientMixin if the widget should persist across navigation.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在异步代码中调用 setState() 前检查 'mounted' 属性。",
    "在 dispose() 方法中取消订阅或 future，以防止回调触发。",
    "如果小部件应在导航中保持存活，使用带有 AutomaticKeepAliveClientMixin 的 StatefulWidget。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://api.flutter.dev/flutter/widgets/State/setState.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}