ScenarioAssetBundle class
The bundle a scenario reads its assets through: one that caches values, never futures.
rootBundle is a CachingAssetBundle, which memoizes the future of a
read. Under fake time that future belongs to the fake zone — it completes
when a pump flushes the fake microtask queue and at no other moment. Hand it
to tester.runAsync, where no pump can run, and the scenario stops dead:
no error, no output, until something far away times out.
Neither half of that is exotic. A screen showing an SVG puts the key in the
cache; a later step reading the same SVG inside runAsync is what the
blank-screen hint recommends. One screen and one step is the whole recipe.
So this caches what came back rather than the promise of it. A hit is a
SynchronousFuture, which resolves in whichever zone awaits it and
schedules nothing; a miss inside runAsync starts its own read, on the real
event loop, and completes there. No future here can be completable by only
one zone.
The cost of that is the cache being useless until the first read returns: callers that all ask before then each start their own read, where CachingAssetBundle would have handed them one future. That is a few extra platform reads in the first frame of a scenario, and it is the trade the whole class is — sharing an in-flight read is exactly the thing that deadlocks.
A scenario has one, reachable as s.assets and installed over the tree it
pumps, so anything reaching for DefaultAssetBundle.of(context) — an
Image.asset, an AssetImage, a SvgPicture.asset — is already reading
through it.
- Inheritance
-
- Object
- AssetBundle
- ScenarioAssetBundle
Constructors
- ScenarioAssetBundle({AssetBundle? source})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- readsInFlight → int
-
Reads started here and not finished — the count a scenario reads to know
that work it cannot see is genuinely in flight, rather than taking a turn
of the real event loop to guess. See
landRealWork.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → void -
If this is a caching asset bundle, clear all cached data.
override
-
evict(
String key) → void -
If this is a caching asset bundle, and the given key describes a cached
asset, then evict the asset from the cache so that the next time it is
loaded, the cache will be reread from the asset bundle.
override
-
load(
String key) → Future< ByteData> -
Retrieve a binary resource from the asset bundle as a data stream.
override
-
loadBuffer(
String key) → Future< ImmutableBuffer> -
Retrieve a binary resource from the asset bundle as an immutable
buffer.
override
-
loadString(
String key, {bool cache = true}) → Future< String> -
Retrieve a string from the asset bundle.
override
-
loadStructuredBinaryData<
T> (String key, FutureOr< T> parser(ByteData data)) → Future<T> -
Retrieve ByteData from the asset bundle, parse it with the given function,
and return that function's result.
override
-
loadStructuredData<
T> (String key, Future< T> parser(String value)) → Future<T> -
Retrieve a string from the asset bundle, parse it with the given function,
and return that function's result.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited