Created
May 7, 2021 02:49
-
-
Save diegoveloper/9b19aff915202f1266ff6dad1b6b424d to your computer and use it in GitHub Desktop.
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
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