Skip to content

Instantly share code, notes, and snippets.

@kenreilly
Last active July 6, 2019 00:58
Show Gist options
  • Save kenreilly/5d01e9870f467945937622a0a6106758 to your computer and use it in GitHub Desktop.
Save kenreilly/5d01e9870f467945937622a0a6106758 to your computer and use it in GitHub Desktop.
AnimatedBackground class for the Flutter scrolling animation demo
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