Created
August 23, 2019 05:33
-
-
Save kenreilly/b837e8da41111c239d90cdda3d576360 to your computer and use it in GitHub Desktop.
Flutter for Web example background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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