drainAndReport static method
Drains persisted native crashes from prior runs and re-emits each through Log.f. Each record is acked back to the plugin after successful re-emit so the underlying file is deleted. Errors talking to the channel are swallowed — crash drain must never block app start.
Implementation
static Future<void> drainAndReport({MethodChannel? channel}) async {
final ch = channel ?? _channel;
final List<Object?> raw;
try {
final res = await ch.invokeMethod<List<Object?>>('drainPending');
raw = res ?? const [];
} on MissingPluginException {
return;
} catch (e, st) {
Log.tag('ux.crash').w('drainPending failed', error: e, stackTrace: st);
return;
}
for (final entry in raw) {
if (entry is! Map) continue;
final m = entry.cast<Object?, Object?>();
final id = m['id']?.toString();
_report(m);
if (id == null) continue;
try {
await ch.invokeMethod<void>('ackCrash', id);
} catch (e, st) {
Log.tag('ux.crash').w('ackCrash failed', error: e, stackTrace: st);
}
}
}