In this article i created a simple splash screen without using any external third party library just use Animation , AnimationController, Duration and Flutter logo.
In that i first created animationController and set timer for gives animation to image.
After that added animation layout in short added a type of animation.
After completing this added Duration for stop splash screen to 5 seconds. And call navigation page. Thats solve
After completing this added Duration for stop splash screen to 5 seconds. And call navigation page. Thats solve
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_splash_screen/homeScreen.dart'; | |
void main() { | |
runApp(new MaterialApp( | |
home: new ScaleAnimation(), | |
)); | |
} | |
class ScaleAnimation extends StatefulWidget { | |
@override | |
_ScaleAnimationState createState() => _ScaleAnimationState(); | |
} | |
class _ScaleAnimationState extends State<ScaleAnimation> | |
with SingleTickerProviderStateMixin { | |
AnimationController animationController; | |
Animation<double> animation; | |
startTimer(){ | |
var duration = new Duration(seconds: 5); | |
return new Timer(duration,navigatorPage); | |
} | |
navigatorPage(){ | |
Navigator.push(context, MaterialPageRoute(builder: (context) => HomeScreen())); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
animationController = AnimationController( | |
vsync: this, duration: Duration(seconds: 2,), | |
); | |
animation = CurvedAnimation( | |
parent: animationController, | |
curve: Curves.bounceInOut, | |
); | |
animationController.forward(); | |
startTimer(); | |
} | |
@override | |
void dispose() { | |
animationController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text("Scale Animation")), | |
body: Center( | |
child: ScaleTransition( | |
scale: animation, | |
child: Container( | |
height: 100, | |
width: 100, | |
child: FlutterLogo(), | |
), | |
), | |
), | |
); | |
} | |
} |