Skip to content

Instantly share code, notes, and snippets.

@kenreilly
Created August 23, 2019 05:33
Show Gist options
  • Save kenreilly/b837e8da41111c239d90cdda3d576360 to your computer and use it in GitHub Desktop.
Save kenreilly/b837e8da41111c239d90cdda3d576360 to your computer and use it in GitHub Desktop.
Flutter for Web example background
import 'package:flutter_web/material.dart';
class Background extends AnimatedWidget {
Background({ Key key, @required this.image, @required this.listenable })
: super(key: key, listenable: listenable);
final AssetImage image;
final ScrollController listenable;
@override
Widget build(BuildContext context) {
double offset = listenable.hasClients ? listenable.offset : 0;
ScrollPosition position = listenable.hasClients ? listenable.position : null;
double extent = (position == null) ? 1 : position.maxScrollExtent * 1.2;
double align = (offset / extent);
return Container(
constraints: BoxConstraints.expand(),
child: Image(
image: image,
alignment: Alignment(0, align),
fit: BoxFit.cover
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment