diagnostic_describe_all_properties
公共属性未在 'debugFillProperties' 或 'debugDescribeChildren' 中描述。
描述
#当实现 Diagnosticable
的类具有公共属性,但该属性未作为属性添加到 debugFillProperties
或 debugDescribeChildren
方法中时,分析器会产生此诊断。
示例
#以下代码产生此诊断,因为属性 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));
}
}
常见修复方法
#如果未重写 debugFillProperties
或 debugDescribeChildren
方法,则添加一个。
在 debugFillProperties
或 debugDescribeChildren
方法中添加属性描述
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));
}
}