inspect static method
Walks the entire tree and returns a JSON with all widgets that contain data relevant for testing.
The JSON includes:
timestamp: when the snapshot was takenwidget_count: number of widgets foundwidgets: list of entries, each withtype,depth, and data depending on the type (value, label, enabled, key, x, y, w, h)
Implementation
static Map<String, dynamic> inspect() {
final root = WidgetsBinding.instance.rootElement;
if (root == null) {
return {
'timestamp': DateTime.now().toUtc().toIso8601String(),
'widget_count': 0,
'widgets': <Map<String, dynamic>>[],
'error': 'rootElement not available',
};
}
final result = <Map<String, dynamic>>[];
_walk(root, 0, result);
// Sanitize the entire result before returning: any NaN or Infinite double
// (from positions, Slider.value/min/max, etc.) is converted to null
// so that jsonEncode never fails due to non-serializable values.
final sanitized = sanitizeList(result);
return {
'timestamp': DateTime.now().toUtc().toIso8601String(),
'widget_count': sanitized.length,
'widgets': sanitized,
};
}