Advertisement
k4ilham

splash ui 3

Jul 10th, 2021
1,466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.41 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. import 'dart:async';
  10. import 'package:flutter/material.dart';
  11.  
  12. class MyCustomSplashScreen extends StatefulWidget {
  13.   @override
  14.   _MyCustomSplashScreenState createState() => _MyCustomSplashScreenState();
  15. }
  16.  
  17. class _MyCustomSplashScreenState extends State<MyCustomSplashScreen>
  18.     with TickerProviderStateMixin {
  19.   double _fontSize = 2;
  20.   double _containerSize = 1.5;
  21.   double _textOpacity = 0.0;
  22.   double _containerOpacity = 0.0;
  23.  
  24.   AnimationController _controller;
  25.   Animation<double> animation1;
  26.  
  27.   @override
  28.   void initState() {
  29.     super.initState();
  30.  
  31.     _controller =
  32.         AnimationController(vsync: this, duration: Duration(seconds: 3));
  33.  
  34.     animation1 = Tween<double>(begin: 40, end: 20).animate(CurvedAnimation(
  35.         parent: _controller, curve: Curves.fastLinearToSlowEaseIn))
  36.       ..addListener(() {
  37.         setState(() {
  38.           _textOpacity = 1.0;
  39.         });
  40.       });
  41.  
  42.     _controller.forward();
  43.  
  44.     Timer(Duration(seconds: 2), () {
  45.       setState(() {
  46.         _fontSize = 1.06;
  47.       });
  48.     });
  49.  
  50.     Timer(Duration(seconds: 2), () {
  51.       setState(() {
  52.         _containerSize = 2;
  53.         _containerOpacity = 1;
  54.       });
  55.     });
  56.  
  57.     Timer(Duration(seconds: 4), () {
  58.       setState(() {
  59.         Navigator.pushReplacement(context, PageTransition(SecondPage()));
  60.       });
  61.     });
  62.   }
  63.  
  64.   @override
  65.   void dispose() {
  66.     _controller.dispose();
  67.     super.dispose();
  68.   }
  69.  
  70.   @override
  71.   Widget build(BuildContext context) {
  72.     double _width = MediaQuery.of(context).size.width;
  73.     double _height = MediaQuery.of(context).size.height;
  74.  
  75.     return Scaffold(
  76.       backgroundColor: Colors.deepPurple,
  77.       body: Stack(
  78.         children: [
  79.           Column(
  80.             children: [
  81.               AnimatedContainer(
  82.                 duration: Duration(milliseconds: 2000),
  83.                 curve: Curves.fastLinearToSlowEaseIn,
  84.                 height: _height / _fontSize
  85.               ),
  86.               AnimatedOpacity(
  87.                 duration: Duration(milliseconds: 1000),
  88.                 opacity: _textOpacity,
  89.                 child: Text(
  90.                   'YOUR APP\'S NAME',
  91.                   style: TextStyle(
  92.                     color: Colors.white,
  93.                     fontWeight: FontWeight.bold,
  94.                     fontSize: animation1.value,
  95.                   ),
  96.                 ),
  97.               ),
  98.             ],
  99.           ),
  100.           Center(
  101.             child: AnimatedOpacity(
  102.               duration: Duration(milliseconds: 2000),
  103.               curve: Curves.fastLinearToSlowEaseIn,
  104.               opacity: _containerOpacity,
  105.               child: AnimatedContainer(
  106.                 duration: Duration(milliseconds: 2000),
  107.                 curve: Curves.fastLinearToSlowEaseIn,
  108.                 height: _width / _containerSize,
  109.                 width: _width / _containerSize,
  110.                 alignment: Alignment.center,
  111.                 decoration: BoxDecoration(
  112.                   color: Colors.white,
  113.                   borderRadius: BorderRadius.circular(30),
  114.                 ),
  115.                 // child: Image.asset('assets/images/file_name.png')
  116.                 child: Text(
  117.                   'YOUR APP\'S LOGO',
  118.                 ),
  119.               ),
  120.             ),
  121.           ),
  122.         ],
  123.       ),
  124.     );
  125.   }
  126. }
  127.  
  128. class PageTransition extends PageRouteBuilder {
  129.   final Widget page;
  130.  
  131.   PageTransition(this.page)
  132.       : super(
  133.           pageBuilder: (context, animation, anotherAnimation) => page,
  134.           transitionDuration: Duration(milliseconds: 2000),
  135.           transitionsBuilder: (context, animation, anotherAnimation, child) {
  136.             animation = CurvedAnimation(
  137.               curve: Curves.fastLinearToSlowEaseIn,
  138.               parent: animation,
  139.             );
  140.             return Align(
  141.               alignment: Alignment.bottomCenter,
  142.               child: SizeTransition(
  143.                 sizeFactor: animation,
  144.                 child: page,
  145.                 axisAlignment: 0,
  146.               ),
  147.             );
  148.           },
  149.         );
  150. }
  151.  
  152. class SecondPage extends StatelessWidget {
  153.   @override
  154.   Widget build(BuildContext context) {
  155.     return Scaffold(
  156.       backgroundColor: Colors.white,
  157.       appBar: AppBar(
  158.         brightness: Brightness.dark,
  159.         backgroundColor: Colors.deepPurple,
  160.         centerTitle: true,
  161.         title: Text(
  162.           'YOUR APP\'S NAME',
  163.           style: TextStyle(
  164.             color: Colors.white,
  165.             fontWeight: FontWeight.bold,
  166.             fontSize: 20,
  167.           ),
  168.         ),
  169.       ),
  170.     );
  171.   }
  172. }
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement