Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save diegoveloper/9b19aff915202f1266ff6dad1b6b424d to your computer and use it in GitHub Desktop.
Save diegoveloper/9b19aff915202f1266ff6dad1b6b424d to your computer and use it in GitHub Desktop.
class GradientAnimation extends StatefulWidget {
@override
_GradientAnimationState createState() => _GradientAnimationState();
}
class _GradientAnimationState extends State<GradientAnimation> with SingleTickerProviderStateMixin {
AnimationController _controller;
final _max = 1.2;
bool _covered = false;
@override
void initState() {
_controller = AnimationController(
vsync: this,
upperBound: _max,
duration: const Duration(milliseconds: 1500),
);
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
extendBody: true,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.animation),
onPressed: () {
if (!_covered) {
_controller.forward();
} else {
_controller.reverse();
}
_covered = !_covered;
},
),
body: Stack(
children: [
Container(
color: Colors.black,
),
AnimatedBuilder(
animation: _controller,
builder: (context, _) {
final value = _controller.value;
return Positioned(
bottom: 0,
left: 0,
width: size.width,
height: size.height * value,
child: Transform.translate(
offset: Offset(0.0, 100),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(
top: Radius.circular(size.width / _max * (_max - value)),
),
boxShadow: [
BoxShadow(
blurRadius: 60,
spreadRadius: 70,
offset: Offset(0.0, 1.0),
color: Colors.white,
)
],
),
),
),
);
},
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment