跳到主要內容

diagnostic_describe_all_properties

公共屬性未在 'debugFillProperties' 或 'debugDescribeChildren' 中描述。

描述

#

當實現 Diagnosticable 的類具有公共屬性,但該屬性未作為屬性新增到 debugFillPropertiesdebugDescribeChildren 方法中時,分析器會產生此診斷。

示例

#

以下程式碼產生此診斷,因為屬性 p2 未新增到 debugFillProperties 方法中

dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class C extends Widget {
  bool get p1 => true;

  bool get p2 => false;

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DiagnosticsProperty<bool>('p1', p1));
  }
}

常見修復方法

#

如果未重寫 debugFillPropertiesdebugDescribeChildren 方法,則新增一個。

debugFillPropertiesdebugDescribeChildren 方法中新增屬性描述

dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class C extends Widget {
  bool get p1 => true;

  bool get p2 => false;

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DiagnosticsProperty<bool>('p1', p1));
    properties.add(DiagnosticsProperty<bool>('p2', p2));
  }
}