Created
August 28, 2018 11:54
-
-
Save peekpt/da61c96ba969f1a6e4dc1779629d41af to your computer and use it in GitHub Desktop.
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 the splash.dart into your main app and use like: | |
// ex: Splash(iconData:Icons.restaurant, label: 'MY APP',); | |
import 'package:flutter/material.dart'; | |
class Splash extends StatefulWidget { | |
final IconData iconData; | |
final String label; | |
Splash({Key key, @required this.iconData, this.label}) : super(key: key); | |
@override | |
_SplashState createState() => _SplashState(); | |
} | |
class _SplashState extends State<Splash> with SingleTickerProviderStateMixin { | |
Animation growAnimation; | |
AnimationController animationController; | |
@override | |
void initState() { | |
super.initState(); | |
animationController = AnimationController( | |
vsync: this, | |
duration: Duration(milliseconds: 800), | |
); | |
growAnimation = Tween(begin: 0.0, end: 1.0).animate(animationController); | |
animationController.forward(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
child: _LogoAnimation( | |
icon: widget.iconData, | |
label: widget.label, | |
animation: growAnimation, | |
)), | |
); | |
} | |
@override | |
void dispose() { | |
// TODO: implement dispose | |
animationController.dispose(); | |
super.dispose(); | |
} | |
} | |
class _LogoAnimation extends AnimatedWidget { | |
final IconData icon; | |
final String label; | |
_LogoAnimation({Key key, Animation animation, this.icon, this.label}) | |
: super(key: key, listenable: animation); | |
@override | |
Widget build(BuildContext context) { | |
Animation animation = listenable; | |
var fColor = Theme.of(context).cardColor; | |
var bColor = Theme.of(context).primaryColor; | |
return Scaffold( | |
backgroundColor: bColor, | |
body: Opacity( | |
child: Stack( | |
fit: StackFit.expand, | |
children: <Widget>[ | |
// Progress layer | |
Center( | |
child: Container( | |
height: animation.value * 180.0, | |
width: animation.value * 180.0, | |
child: CircularProgressIndicator( | |
strokeWidth: animation.value * 10.0, | |
valueColor: AlwaysStoppedAnimation<Color>(fColor), | |
), | |
), | |
), | |
// Icon Layer | |
Center( | |
child: Container( | |
width: animation.value * 150.0, | |
height: animation.value * 150.0, | |
child: icon == null | |
? FlutterLogo() | |
: CircleAvatar( | |
child: Icon( | |
icon, | |
size: animation.value * 90.0, | |
), | |
backgroundColor: fColor, | |
), | |
), | |
), | |
// App name layer | |
Padding( | |
padding: EdgeInsets.only(top: animation.value * 300), | |
child: Center( | |
child: Text( | |
label ?? '', | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
fontSize: animation.value * 24.0, | |
color: fColor, | |
fontWeight: FontWeight.bold), | |
)), | |
) | |
], | |
), | |
opacity: animation.value, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment