read static method
Reads the fields of the state the app captured, described by the
inspect block of a state.data reply.
Throws a LiveStateFieldsUnavailable when the app's build can't answer: a release or profile build, or a runtime whose VM service doesn't support reading objects.
Implementation
static Future<List<LiveStateField>> read(
LiveApp app,
Map<String, Object?> inspect, {
Duration? timeout,
}) async {
final String? variable = inspect['variable'] as String?;
final String? encoder = inspect['encoder'] as String?;
if (variable == null || encoder == null) {
throw const LiveStateFieldsUnavailable(
'This app\'s Nylo version doesn\'t expose its state fields.',
);
}
final Set<String> skip = {
for (final Object? name in inspect['skip'] as List? ?? const []) '$name',
};
try {
final String library = await _library(
app,
inspect['library'] as String?,
timeout,
);
final Map<String, Object?> state = await _capturedState(
app,
library,
variable,
timeout,
);
if (state.isEmpty) return const [];
final List<_RawField> raw = _ownFields(state, skip);
if (raw.isEmpty) return const [];
return await _encode(app, library, encoder, raw, timeout);
} on JsonRpcException catch (e) {
throw LiveStateFieldsUnavailable(
'The app didn\'t let Metro read its state fields (${e.details}).',
);
}
}