load static method
- Iterable<
ParallaxData> dataList, { - Vector2? size,
- Vector2? baseVelocity,
- Vector2? velocityMultiplierDelta,
- ImageRepeat repeat = ImageRepeat.repeatX,
- Alignment alignment = Alignment.bottomLeft,
- LayerFill fill = LayerFill.height,
- Images? images,
- FilterQuality? filterQuality,
Note that this method only should be used if all of your layers should have the same layer arguments (how the images should be repeated, aligned and filled), otherwise load the ParallaxLayers individually and use the normal constructor.
load takes a list of paths to all the images that you want to use in the
parallax.
Optionally arguments for the baseVelocity
and velocityMultiplierDelta
can be passed in, baseVelocity
defines what the base velocity of the
layers should be and velocityMultiplierDelta
defines how the velocity
should change the closer the layer is (velocityMultiplierDelta ^ n
,
where n
is the layer index).
Arguments for how all the images should repeat (repeat
),
which edge it should align with (alignment
), which axis it should fill
the image on (fill
) and images
which is the image cache that should be
used can also be passed in.
If no image cache is set, the global flame cache is used.
Implementation
static Future<Parallax> load(
Iterable<ParallaxData> dataList, {
Vector2? size,
Vector2? baseVelocity,
Vector2? velocityMultiplierDelta,
ImageRepeat repeat = ImageRepeat.repeatX,
Alignment alignment = Alignment.bottomLeft,
LayerFill fill = LayerFill.height,
Images? images,
FilterQuality? filterQuality,
}) async {
final velocityDelta = velocityMultiplierDelta ?? Vector2.all(1.0);
final layers = await Future.wait<ParallaxLayer>(
dataList.mapIndexed((depth, data) async {
final velocityMultiplier =
List.filled(depth, velocityDelta).fold<Vector2>(
velocityDelta,
(previousValue, delta) => previousValue.clone()..multiply(delta),
);
final renderer = await data.load(
repeat,
alignment,
fill,
images,
filterQuality,
);
return ParallaxLayer(
renderer,
velocityMultiplier: velocityMultiplier,
);
}),
);
return Parallax(
layers,
size: size,
baseVelocity: baseVelocity,
);
}