provide_deprecation_message
透過 @Deprecated("message")
提供棄用訊息。
詳細資訊
#務必在 Deprecated
建構子中指定棄用訊息 (包含遷移指示和/或移除時程)。
不良範例
dart
@deprecated
void oldFunction(arg1, arg2) {}
良好範例
dart
@Deprecated("""
[oldFunction] is being deprecated in favor of [newFunction] (with slightly
different parameters; see [newFunction] for more information). [oldFunction]
will be removed on or after the 4.0.0 release.
""")
void oldFunction(arg1, arg2) {}
啟用
#若要啟用 provide_deprecation_message
規則,請在您的 analysis_options.yaml
檔案中,於 linter > rules 下新增 provide_deprecation_message
analysis_options.yaml
yaml
linter:
rules:
- provide_deprecation_message
如果您改用 YAML 地圖語法來設定 linter 規則,請在 linter > rules 下新增 provide_deprecation_message: true
analysis_options.yaml
yaml
linter:
rules:
provide_deprecation_message: true
除非另有說明,本網站的文件反映 Dart 3.7.1 版本。頁面最後更新於 2025-03-07。 檢視原始碼 或 回報問題。