cachedFuture top-level constant
CachedFuture
const cachedFuture
Marks a method as a cache-method that returns a stored Future rather than creating a new one on each call.
When pass_existing_future_to_future_builder sees a method annotated with
@cachedFuture passed to FutureBuilder(future:), it will not flag the
call — the annotation is an explicit signal that the method manages its
own caching internally.
Use this when the heuristic-based exemption (private method on a class
with a Future<T>? field) does not apply to your naming convention.
class _MyState extends State<MyWidget> {
Future<Data>? _cache;
@cachedFuture
Future<Data> _load(String id) {
return _cache ??= _repository.fetch(id);
}
@override
Widget build(BuildContext context) {
return FutureBuilder<Data>(
future: _load(widget.id), // OK — @cachedFuture suppresses the lint
builder: (context, snapshot) => ...,
);
}
}
Implementation
const cachedFuture = CachedFuture();