Use DiagnosticableMixin instead of Diagnosticable for some conditionals. (#49726)
This PR fixes #49647 by changing DiagnosticableMixin.toDiagnosticsNode and other things to accept DiagnosticableMixin instead of requiring Diagnosticable.
This commit is contained in:
parent
6ee8b6546b
commit
e7baef08a1
@ -8,7 +8,7 @@ import 'colors.dart';
|
|||||||
|
|
||||||
/// An [IconThemeData] subclass that automatically resolves its [color] when retrieved
|
/// An [IconThemeData] subclass that automatically resolves its [color] when retrieved
|
||||||
/// using [IconTheme.of].
|
/// using [IconTheme.of].
|
||||||
class CupertinoIconThemeData extends IconThemeData with DiagnosticableMixin {
|
class CupertinoIconThemeData extends IconThemeData with DiagnosticableMixin implements Diagnosticable {
|
||||||
/// Creates a [CupertinoIconThemeData].
|
/// Creates a [CupertinoIconThemeData].
|
||||||
///
|
///
|
||||||
/// The opacity applies to both explicit and default icon colors. The value
|
/// The opacity applies to both explicit and default icon colors. The value
|
||||||
|
@ -351,7 +351,7 @@ class FlutterErrorDetails extends Diagnosticable {
|
|||||||
return longMessage;
|
return longMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
Diagnosticable _exceptionToDiagnosticable() {
|
DiagnosticableMixin _exceptionToDiagnosticable() {
|
||||||
if (exception is FlutterError) {
|
if (exception is FlutterError) {
|
||||||
return exception as FlutterError;
|
return exception as FlutterError;
|
||||||
}
|
}
|
||||||
@ -374,7 +374,7 @@ class FlutterErrorDetails extends Diagnosticable {
|
|||||||
if (kReleaseMode) {
|
if (kReleaseMode) {
|
||||||
return DiagnosticsNode.message(formatException());
|
return DiagnosticsNode.message(formatException());
|
||||||
}
|
}
|
||||||
final Diagnosticable diagnosticable = _exceptionToDiagnosticable();
|
final DiagnosticableMixin diagnosticable = _exceptionToDiagnosticable();
|
||||||
DiagnosticsNode summary;
|
DiagnosticsNode summary;
|
||||||
if (diagnosticable != null) {
|
if (diagnosticable != null) {
|
||||||
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
|
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
|
||||||
@ -388,7 +388,7 @@ class FlutterErrorDetails extends Diagnosticable {
|
|||||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||||
super.debugFillProperties(properties);
|
super.debugFillProperties(properties);
|
||||||
final DiagnosticsNode verb = ErrorDescription('thrown${ context != null ? ErrorDescription(" $context") : ""}');
|
final DiagnosticsNode verb = ErrorDescription('thrown${ context != null ? ErrorDescription(" $context") : ""}');
|
||||||
final Diagnosticable diagnosticable = _exceptionToDiagnosticable();
|
final DiagnosticableMixin diagnosticable = _exceptionToDiagnosticable();
|
||||||
if (exception is NullThrownError) {
|
if (exception is NullThrownError) {
|
||||||
properties.add(ErrorDescription('The null value was $verb.'));
|
properties.add(ErrorDescription('The null value was $verb.'));
|
||||||
} else if (exception is num) {
|
} else if (exception is num) {
|
||||||
|
@ -2640,7 +2640,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
|
|||||||
Map<String, Object> toJsonMap(DiagnosticsSerializationDelegate delegate) {
|
Map<String, Object> toJsonMap(DiagnosticsSerializationDelegate delegate) {
|
||||||
final T v = value;
|
final T v = value;
|
||||||
List<Map<String, Object>> properties;
|
List<Map<String, Object>> properties;
|
||||||
if (delegate.expandPropertyValues && delegate.includeProperties && v is Diagnosticable && getProperties().isEmpty) {
|
if (delegate.expandPropertyValues && delegate.includeProperties && v is DiagnosticableMixin && getProperties().isEmpty) {
|
||||||
// Exclude children for expanded nodes to avoid cycles.
|
// Exclude children for expanded nodes to avoid cycles.
|
||||||
delegate = delegate.copyWith(subtreeDepth: 0, includeProperties: false);
|
delegate = delegate.copyWith(subtreeDepth: 0, includeProperties: false);
|
||||||
properties = DiagnosticsNode.toJsonList(
|
properties = DiagnosticsNode.toJsonList(
|
||||||
@ -2666,7 +2666,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
|
|||||||
json['exception'] = exception.toString();
|
json['exception'] = exception.toString();
|
||||||
json['propertyType'] = propertyType.toString();
|
json['propertyType'] = propertyType.toString();
|
||||||
json['defaultLevel'] = describeEnum(_defaultLevel);
|
json['defaultLevel'] = describeEnum(_defaultLevel);
|
||||||
if (value is Diagnosticable || value is DiagnosticsNode)
|
if (value is DiagnosticableMixin || value is DiagnosticsNode)
|
||||||
json['isDiagnosticableValue'] = true;
|
json['isDiagnosticableValue'] = true;
|
||||||
if (v is num)
|
if (v is num)
|
||||||
// Workaround for https://github.com/flutter/flutter/issues/39937#issuecomment-529558033.
|
// Workaround for https://github.com/flutter/flutter/issues/39937#issuecomment-529558033.
|
||||||
@ -2846,7 +2846,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
|
|||||||
if (object is DiagnosticsNode) {
|
if (object is DiagnosticsNode) {
|
||||||
return object.getProperties();
|
return object.getProperties();
|
||||||
}
|
}
|
||||||
if (object is Diagnosticable) {
|
if (object is DiagnosticableMixin) {
|
||||||
return object.toDiagnosticsNode(style: style).getProperties();
|
return object.toDiagnosticsNode(style: style).getProperties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2860,7 +2860,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
|
|||||||
if (object is DiagnosticsNode) {
|
if (object is DiagnosticsNode) {
|
||||||
return object.getChildren();
|
return object.getChildren();
|
||||||
}
|
}
|
||||||
if (object is Diagnosticable) {
|
if (object is DiagnosticableMixin) {
|
||||||
return object.toDiagnosticsNode(style: style).getChildren();
|
return object.toDiagnosticsNode(style: style).getChildren();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2870,8 +2870,8 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
|
|||||||
|
|
||||||
/// [DiagnosticsNode] that lazily calls the associated [Diagnosticable] [value]
|
/// [DiagnosticsNode] that lazily calls the associated [Diagnosticable] [value]
|
||||||
/// to implement [getChildren] and [getProperties].
|
/// to implement [getChildren] and [getProperties].
|
||||||
class DiagnosticableNode<T extends Diagnosticable> extends DiagnosticsNode {
|
class DiagnosticableNode<T extends DiagnosticableMixin> extends DiagnosticsNode {
|
||||||
/// Create a diagnostics describing a [Diagnosticable] value.
|
/// Create a diagnostics describing a [DiagnosticableMixin] value.
|
||||||
///
|
///
|
||||||
/// The [value] argument must not be null.
|
/// The [value] argument must not be null.
|
||||||
DiagnosticableNode({
|
DiagnosticableNode({
|
||||||
@ -2991,7 +2991,7 @@ String describeEnum(Object enumEntry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builder to accumulate properties and configuration used to assemble a
|
/// Builder to accumulate properties and configuration used to assemble a
|
||||||
/// [DiagnosticsNode] from a [Diagnosticable] object.
|
/// [DiagnosticsNode] from a [DiagnosticableMixin] object.
|
||||||
class DiagnosticPropertiesBuilder {
|
class DiagnosticPropertiesBuilder {
|
||||||
/// Creates a [DiagnosticPropertiesBuilder] with [properties] initialize to
|
/// Creates a [DiagnosticPropertiesBuilder] with [properties] initialize to
|
||||||
/// an empty array.
|
/// an empty array.
|
||||||
@ -3053,10 +3053,8 @@ abstract class Diagnosticable with DiagnosticableMixin {
|
|||||||
const Diagnosticable();
|
const Diagnosticable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A mixin class that provides the implementation for [Diagnosticable].
|
/// A mixin class for providing string and [DiagnosticsNode] debug
|
||||||
///
|
/// representations describing the properties of an object.
|
||||||
/// This mixin can be used to add diagnostics to a class which already has an
|
|
||||||
/// base class.
|
|
||||||
///
|
///
|
||||||
/// The string debug representation is generated from the intermediate
|
/// The string debug representation is generated from the intermediate
|
||||||
/// [DiagnosticsNode] representation. The [DiagnosticsNode] representation is
|
/// [DiagnosticsNode] representation. The [DiagnosticsNode] representation is
|
||||||
@ -3108,9 +3106,9 @@ mixin DiagnosticableMixin {
|
|||||||
/// relationship between the parent and the node. For example, pass
|
/// relationship between the parent and the node. For example, pass
|
||||||
/// [DiagnosticsTreeStyle.offstage] to indicate that a node is offstage.
|
/// [DiagnosticsTreeStyle.offstage] to indicate that a node is offstage.
|
||||||
DiagnosticsNode toDiagnosticsNode({ String name, DiagnosticsTreeStyle style }) {
|
DiagnosticsNode toDiagnosticsNode({ String name, DiagnosticsTreeStyle style }) {
|
||||||
return DiagnosticableNode<Diagnosticable>(
|
return DiagnosticableNode<DiagnosticableMixin>(
|
||||||
name: name,
|
name: name,
|
||||||
value: this as Diagnosticable,
|
value: this,
|
||||||
style: style,
|
style: style,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -3338,8 +3336,8 @@ mixin DiagnosticableMixin {
|
|||||||
/// See also:
|
/// See also:
|
||||||
///
|
///
|
||||||
/// * [DiagnosticableTreeMixin], a mixin that implements this class.
|
/// * [DiagnosticableTreeMixin], a mixin that implements this class.
|
||||||
/// * [Diagnosticable], which should be used instead of this class to provide
|
/// * [DiagnosticableMixin], which should be used instead of this class to
|
||||||
/// diagnostics for objects without children.
|
/// provide diagnostics for objects without children.
|
||||||
abstract class DiagnosticableTree extends Diagnosticable {
|
abstract class DiagnosticableTree extends Diagnosticable {
|
||||||
/// Abstract const constructor. This constructor enables subclasses to provide
|
/// Abstract const constructor. This constructor enables subclasses to provide
|
||||||
/// const constructors so that they can be used in const expressions.
|
/// const constructors so that they can be used in const expressions.
|
||||||
@ -3643,7 +3641,7 @@ abstract class DiagnosticsSerializationDelegate {
|
|||||||
/// will be included.
|
/// will be included.
|
||||||
bool get includeProperties;
|
bool get includeProperties;
|
||||||
|
|
||||||
/// Whether properties that have a [Diagnosticable] as value should be
|
/// Whether properties that have a [DiagnosticableMixin] as value should be
|
||||||
/// expanded.
|
/// expanded.
|
||||||
bool get expandPropertyValues;
|
bool get expandPropertyValues;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ abstract class TickerProvider {
|
|||||||
Ticker createTicker(TickerCallback onTick);
|
Ticker createTicker(TickerCallback onTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jacobr): make Ticker Diagnosticable to simplify reporting errors
|
// TODO(jacobr): make Ticker use DiagnosticableMixin to simplify reporting errors
|
||||||
// related to a ticker.
|
// related to a ticker.
|
||||||
/// Calls its callback once per animation frame.
|
/// Calls its callback once per animation frame.
|
||||||
///
|
///
|
||||||
|
@ -110,7 +110,7 @@ class KeySet<T extends KeyboardKey> {
|
|||||||
/// This is a thin wrapper around a [Set], but changes the equality comparison
|
/// This is a thin wrapper around a [Set], but changes the equality comparison
|
||||||
/// from an identity comparison to a contents comparison so that non-identical
|
/// from an identity comparison to a contents comparison so that non-identical
|
||||||
/// sets with the same keys in them will compare as equal.
|
/// sets with the same keys in them will compare as equal.
|
||||||
class LogicalKeySet extends KeySet<LogicalKeyboardKey> with DiagnosticableMixin {
|
class LogicalKeySet extends KeySet<LogicalKeyboardKey> with DiagnosticableMixin implements Diagnosticable {
|
||||||
/// A constructor for making a [LogicalKeySet] of up to four keys.
|
/// A constructor for making a [LogicalKeySet] of up to four keys.
|
||||||
///
|
///
|
||||||
/// If you need a set of more than four keys, use [LogicalKeySet.fromSet].
|
/// If you need a set of more than four keys, use [LogicalKeySet.fromSet].
|
||||||
@ -201,7 +201,7 @@ class ShortcutMapProperty extends DiagnosticsProperty<Map<LogicalKeySet, Intent>
|
|||||||
///
|
///
|
||||||
/// A [ShortcutManager] is obtained by calling [Shortcuts.of] on the context of
|
/// A [ShortcutManager] is obtained by calling [Shortcuts.of] on the context of
|
||||||
/// the widget that you want to find a manager for.
|
/// the widget that you want to find a manager for.
|
||||||
class ShortcutManager extends ChangeNotifier with DiagnosticableMixin {
|
class ShortcutManager extends ChangeNotifier with DiagnosticableMixin implements Diagnosticable {
|
||||||
/// Constructs a [ShortcutManager].
|
/// Constructs a [ShortcutManager].
|
||||||
///
|
///
|
||||||
/// The [shortcuts] argument must not be null.
|
/// The [shortcuts] argument must not be null.
|
||||||
|
@ -635,7 +635,7 @@ class _DiagnosticsPathNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<_DiagnosticsPathNode> _followDiagnosticableChain(
|
List<_DiagnosticsPathNode> _followDiagnosticableChain(
|
||||||
List<Diagnosticable> chain, {
|
List<DiagnosticableMixin> chain, {
|
||||||
String name,
|
String name,
|
||||||
DiagnosticsTreeStyle style,
|
DiagnosticsTreeStyle style,
|
||||||
}) {
|
}) {
|
||||||
@ -644,7 +644,7 @@ List<_DiagnosticsPathNode> _followDiagnosticableChain(
|
|||||||
return path;
|
return path;
|
||||||
DiagnosticsNode diagnostic = chain.first.toDiagnosticsNode(name: name, style: style);
|
DiagnosticsNode diagnostic = chain.first.toDiagnosticsNode(name: name, style: style);
|
||||||
for (int i = 1; i < chain.length; i += 1) {
|
for (int i = 1; i < chain.length; i += 1) {
|
||||||
final Diagnosticable target = chain[i];
|
final DiagnosticableMixin target = chain[i];
|
||||||
bool foundMatch = false;
|
bool foundMatch = false;
|
||||||
final List<DiagnosticsNode> children = diagnostic.getChildren();
|
final List<DiagnosticsNode> children = diagnostic.getChildren();
|
||||||
for (int j = 0; j < children.length; j += 1) {
|
for (int j = 0; j < children.length; j += 1) {
|
||||||
@ -1550,7 +1550,7 @@ mixin WidgetInspectorService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final Object value = node.value;
|
final Object value = node.value;
|
||||||
if (value is! Diagnosticable) {
|
if (value is! DiagnosticableMixin) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (value is! Element || !isWidgetCreationTracked()) {
|
if (value is! Element || !isWidgetCreationTracked()) {
|
||||||
|
@ -180,7 +180,7 @@ void validatePropertyJsonSerializationHelper(final Map<String, Object> json, Dia
|
|||||||
}
|
}
|
||||||
expect(json['propertyType'], equals(property.propertyType.toString()));
|
expect(json['propertyType'], equals(property.propertyType.toString()));
|
||||||
expect(json.containsKey('defaultLevel'), isTrue);
|
expect(json.containsKey('defaultLevel'), isTrue);
|
||||||
if (property.value is Diagnosticable) {
|
if (property.value is DiagnosticableMixin) {
|
||||||
expect(json['isDiagnosticableValue'], isTrue);
|
expect(json['isDiagnosticableValue'], isTrue);
|
||||||
} else {
|
} else {
|
||||||
expect(json.containsKey('isDiagnosticableValue'), isFalse);
|
expect(json.containsKey('isDiagnosticableValue'), isFalse);
|
||||||
|
@ -322,5 +322,29 @@ void main() {
|
|||||||
expect(description.length, equals(1));
|
expect(description.length, equals(1));
|
||||||
expect(description[0], equals('shortcuts: <Debug Label>'));
|
expect(description[0], equals('shortcuts: <Debug Label>'));
|
||||||
});
|
});
|
||||||
|
test('Shortcuts diagnostics work when manager specified.', () {
|
||||||
|
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
|
||||||
|
|
||||||
|
Shortcuts(
|
||||||
|
manager: ShortcutManager(),
|
||||||
|
shortcuts: <LogicalKeySet, Intent>{
|
||||||
|
LogicalKeySet(
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
LogicalKeyboardKey.keyB,
|
||||||
|
): const Intent(ActivateAction.key)
|
||||||
|
},
|
||||||
|
).debugFillProperties(builder);
|
||||||
|
|
||||||
|
final List<String> description = builder.properties
|
||||||
|
.where((DiagnosticsNode node) {
|
||||||
|
return !node.isFiltered(DiagnosticLevel.info);
|
||||||
|
})
|
||||||
|
.map((DiagnosticsNode node) => node.toString())
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
expect(description.length, equals(2));
|
||||||
|
expect(description[0], equalsIgnoringHashCodes('manager: ShortcutManager#00000(shortcuts: {})'));
|
||||||
|
expect(description[1], equalsIgnoringHashCodes('shortcuts: {{Key A + Key B}: Intent#00000(key: [<ActivateAction>])}'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user