simple_parallax 1.0.1
simple_parallax: ^1.0.1 copied to clipboard
Parallax widgets for Flutter, with a container mode and a per-item mode. Pure Dart, no dependencies, works with any ImageProvider.
Simple Parallax #
Parallax widgets for Flutter, in pure Dart. Two modes, any ImageProvider, and no dependencies
beyond the Flutter SDK.
Install #
flutter pub add simple_parallax
Requires Flutter 3.22 or later.
Container mode #
One background drifting behind a scrolling area. autoSpeed derives the speed from the real scroll
extent, so the background uses exactly the travel overscan gives it and never runs out of image:
SimpleParallaxContainer(
image: const AssetImage('assets/images/background.webp'),
autoSpeed: true,
overscan: 1.5,
child: Column(children: items),
);
| Parameter | Default | Effect |
|---|---|---|
image |
required | Any ImageProvider: asset, network, file or memory. |
child |
required | The scrolling content. |
speed |
0.3 |
Background travel per pixel scrolled. Ignored when autoSpeed is set. |
autoSpeed |
false |
Derives the speed from the scroll extent. |
overscan |
1.5 |
How much taller than the viewport the background is drawn. |
height |
null |
Forces the viewport height instead of using the constraints. |
fit |
BoxFit.cover |
How the background fills its layer. |
alignment |
Alignment.center |
How the background sits inside its layer. |
Item mode #
Each block slides its own background as it crosses the viewport. The item finds the enclosing
Scrollable by itself, so it works in a ListView, a CustomScrollView, or anything else that
scrolls:
ListView(
children: <Widget>[
SimpleParallaxItem(
image: const NetworkImage('https://example.com/cover.jpg'),
height: 300,
child: const Center(child: Text('Chapter one')),
),
],
);
| Parameter | Default | Effect |
|---|---|---|
image |
required | Any ImageProvider. |
child |
null |
Content drawn over the background. |
speed |
1.0 |
Fraction of the available travel used, from 0 to 1. |
overscan |
1.5 |
How much taller than the item the background is drawn. |
height |
screen height | Item height. |
width |
constraints | Item width. |
fit |
BoxFit.cover |
How the background fills its layer. |
SimpleParallaxWidget is a convenience scroll view for a handful of items. Prefer a ListView when
the list is long enough to need lazy building.
SimpleParallaxWidget(
children: <Widget>[
const SimpleParallaxItem(image: AssetImage('assets/a.webp'), height: 300),
Container(height: 400, color: Colors.blueGrey),
],
);
How it performs #
Scrolling repaints the background and nothing else. In container mode the moving layer sits behind a
RepaintBoundary and only its transform is rebuilt, so your content is built once. In item mode the
background is painted by a Flow bound directly to the scroll position, which repaints without
rebuilding a single widget.
Migrating from 0.1.x #
| Before | Now |
|---|---|
imagePath: 'assets/a.webp' |
image: AssetImage('assets/a.webp') |
decal: 1.5 |
overscan: 1.5 |
SimpleParallaxItem(speed: 0.3) |
speed is a 0..1 fraction now, default 1.0 |
SimpleParallaxItem only inside SimpleParallaxWidget |
works inside any scrollable |
autoSpeed needed a GlobalKey on your child |
nothing to pass |
The package is no longer a Flutter plugin: the native platform folders are gone, and so is the
provider dependency.
Dependencies #
None beyond the Flutter SDK.
Tests #
flutter test
License #
MIT, see LICENSE.
