Last active
July 6, 2019 00:58
-
-
Save kenreilly/5d01e9870f467945937622a0a6106758 to your computer and use it in GitHub Desktop.
AnimatedBackground class for the Flutter scrolling animation demo
This file contains 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/material.dart'; | |
import 'dart:math' as math; | |
class AnimatedBackground extends StatefulWidget { | |
AnimatedBackground({Key key, this.controller}) : super(key: key); | |
final ScrollController controller; | |
@override | |
_AnimatedBackgroundState createState() => _AnimatedBackgroundState(); | |
} | |
class _AnimatedBackgroundState extends State<AnimatedBackground> { | |
get offset => widget.controller.hasClients ? widget.controller.offset : 0; | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedBuilder( | |
animation: widget.controller, | |
builder: (BuildContext context, Widget child) { | |
return OverflowBox( | |
maxWidth: double.infinity, | |
alignment: Alignment(4, 3), | |
child: Transform.rotate( | |
angle: ((math.pi * offset) / -1024), | |
child: Icon(Icons.settings, size: 512, color: Colors.white) | |
) | |
); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment