{
  "id": "flutter/const-key-not-found",
  "signature": "FlutterError: 'const' key not found in InheritedWidget context",
  "signature_zh": "FlutterError: 在 InheritedWidget 上下文中未找到 'const' 键",
  "regex": "FlutterError: 'const' key not found in InheritedWidget context",
  "domain": "flutter",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A widget used a const key to access an InheritedWidget, but the InheritedWidget was not in the widget tree above the accessing widget, often due to missing provider or incorrect build context.",
  "root_cause_type": "generic",
  "root_cause_zh": "小部件使用 const 键访问 InheritedWidget，但该 InheritedWidget 不在访问小部件上方的 widget 树中，通常是由于缺少 provider 或构建上下文不正确。",
  "versions": [
    {
      "version": "Flutter 3.10.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Flutter 3.19.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Dart 3.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Replace const key with a non-const key using a random value",
      "why_fails": "The issue is not the const qualifier but the InheritedWidget's absence; changing the key doesn't fix the missing ancestor.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrap the entire app in a MaterialApp to provide default InheritedWidgets",
      "why_fails": "MaterialApp provides MediaQuery and Theme, but the error is about a custom InheritedWidget; MaterialApp won't supply it.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a dummy InheritedWidget at the root with a const key",
      "why_fails": "The dummy widget doesn't provide the required data; the accessing widget still fails to find the correct InheritedWidget.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the InheritedWidget is placed above the accessing widget in the widget tree. For example, wrap the relevant subtree with a provider:\n  class MyProvider extends InheritedWidget {\n    final String data;\n    MyProvider({required this.data, required Widget child}) : super(child: child);\n    static MyProvider of(BuildContext context) {\n      return context.dependOnInheritedWidgetOfExactType<MyProvider>()!;\n    }\n    @override\n    bool updateShouldNotify(MyProvider oldWidget) => data != oldWidget.data;\n  }\nThen use MyProvider in the build method before accessing it.",
      "success_rate": 0.85,
      "how": "Ensure the InheritedWidget is placed above the accessing widget in the widget tree. For example, wrap the relevant subtree with a provider:\n  class MyProvider extends InheritedWidget {\n    final String data;\n    MyProvider({required this.data, required Widget child}) : super(child: child);\n    static MyProvider of(BuildContext context) {\n      return context.dependOnInheritedWidgetOfExactType<MyProvider>()!;\n    }\n    @override\n    bool updateShouldNotify(MyProvider oldWidget) => data != oldWidget.data;\n  }\nThen use MyProvider in the build method before accessing it.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Verify that the BuildContext used to access the InheritedWidget is from a descendant widget. Call 'context.dependOnInheritedWidgetOfExactType' only after the InheritedWidget has been inserted into the tree, e.g., in a child widget's build method.",
      "success_rate": 0.8,
      "how": "Verify that the BuildContext used to access the InheritedWidget is from a descendant widget. Call 'context.dependOnInheritedWidgetOfExactType' only after the InheritedWidget has been inserted into the tree, e.g., in a child widget's build method.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a Provider package (like Riverpod) that manages InheritedWidgets automatically, ensuring proper placement.",
      "success_rate": 0.75,
      "how": "Use a Provider package (like Riverpod) that manages InheritedWidgets automatically, ensuring proper placement.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保 InheritedWidget 位于访问小部件上方的 widget 树中。例如，使用 provider 包装相关子树：\n  class MyProvider extends InheritedWidget {\n    final String data;\n    MyProvider({required this.data, required Widget child}) : super(child: child);\n    static MyProvider of(BuildContext context) {\n      return context.dependOnInheritedWidgetOfExactType<MyProvider>()!;\n    }\n    @override\n    bool updateShouldNotify(MyProvider oldWidget) => data != oldWidget.data;\n  }\n然后在访问之前在 build 方法中使用 MyProvider。",
    "验证用于访问 InheritedWidget 的 BuildContext 来自后代小部件。仅在 InheritedWidget 已插入树后调用 'context.dependOnInheritedWidgetOfExactType'，例如在子小部件的 build 方法中。",
    "使用 Provider 包（如 Riverpod）自动管理 InheritedWidget，确保正确放置。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://api.flutter.dev/flutter/widgets/InheritedWidget-class.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.75,
  "resolvable": "true",
  "first_seen": "2023-06-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}