getStateInspector static method
Get state inspector data
Implementation
static Map<String, dynamic> getStateInspector() {
if (!_enabled) {
return {'error': 'DevTools not enabled'};
}
final allState = <String, dynamic>{};
// Get all Rx states
// ignore: deprecated_member_use_from_same_package
for (final entry in _rxRegistry.entries) {
try {
// ignore: deprecated_member_use_from_same_package
final rx = _getRxById(entry.key);
if (rx != null) {
allState[entry.key] = {
'type': 'Rx',
'name': entry.value.name,
'value': _serializeValue(rx.rawValue),
'createdAt': entry.value.createdAt.toIso8601String(),
'id': entry.key,
};
} else {
// Object was garbage collected
allState[entry.key] = {
'type': 'Rx',
'name': entry.value.name,
'value': '<disposed>',
'status': 'disposed',
};
}
} catch (e) {
allState[entry.key] = {'error': e.toString()};
}
}
// Get all Computed states
for (final entry in _computedRegistry.entries) {
try {
final computed = _getComputedById(entry.key);
if (computed != null) {
allState[entry.key] = {
'type': 'Computed',
'name': entry.value.name,
'value': _serializeValue(computed.value),
'createdAt': entry.value.createdAt.toIso8601String(),
'id': entry.key,
};
} else {
allState[entry.key] = {
'type': 'Computed',
'name': entry.value.name,
'value': '<disposed>',
'status': 'disposed',
};
}
} catch (e) {
allState[entry.key] = {'error': e.toString()};
}
}
// Get store states
final storeStates = store.getAllStateKeys();
for (final key in storeStates) {
try {
// ignore: deprecated_member_use_from_same_package
final state = store.getState<Rx<dynamic>>(key);
allState['store:$key'] = {
'type': 'StoreState',
'name': key,
'value': _serializeValue(state.rawValue),
'id': 'store:$key',
};
} catch (e) {
allState['store:$key'] = {'error': e.toString()};
}
}
// Get Redux stores
for (final entry in _reduxStoreRefs.entries) {
try {
final reduxStore = entry.value;
allState[entry.key] = {
'type': 'ReduxStore',
'name': _stateNodes[entry.key]?.name ?? 'ReduxStore',
'value': _serializeValue(reduxStore.value),
'actionHistoryCount': reduxStore.actionHistory.length,
'id': entry.key,
};
} catch (e) {
allState[entry.key] = {'error': e.toString()};
}
}
return {
'states': allState,
'totalCount': allState.length,
// ignore: deprecated_member_use_from_same_package
'rxCount': _rxRegistry.length,
'computedCount': _computedRegistry.length,
'markCount': _markRegistry.length,
'reduxStoreCount': _reduxStoreRefs.length,
'timestamp': DateTime.now().toIso8601String(),
};
}