panel method
Fetches the panel. Uses a conditional GET and the cache when both are
configured; otherwise this is exactly today's plain get().
Implementation
Future<PanelSchema> panel() async {
final cache = _cache;
final key = _effectiveKey;
final transport = _transport;
final entry = cache != null && key != null
? await _readValid(cache, key)
: null;
// `FilamentConditionalTransport` is a sibling interface of
// `FilamentTransport`, not a subtype — hosts implement both on one
// class, but Dart cannot promote `transport` across this `is` check, so
// the cast below is required. Do not "simplify" it away.
if (transport is FilamentConditionalTransport) {
final conditional = transport as FilamentConditionalTransport;
final response = await conditional.getConditional(
_path,
etag: entry?.cached.etag,
);
if (response.notModified) {
// The cached document just proved current is the one to return.
// Nothing to rewrite — the cache already holds exactly this.
if (entry != null) return entry.panel;
// A 304 with nothing cached to revalidate against should not
// happen — a host only echoes an etag it was sent — but if it
// does, fall through to a plain fetch rather than return nothing.
} else if (response.body != null) {
final panel = PanelSchema.fromJson(response.body!);
if (cache != null && key != null) {
await _writeSafely(
cache,
key,
CachedSchema(
document: jsonEncode(response.body),
etag: response.etag,
),
);
}
return panel;
}
}
final body = await transport.get(_path);
final panel = PanelSchema.fromJson(body);
if (cache != null && key != null) {
await _writeSafely(
cache,
key,
CachedSchema(document: jsonEncode(body), etag: null),
);
}
return panel;
}