[dart] splash

Viewer

  1. import 'package:flutter/material.dart';
  2.  
  3. class SplashScreen extends StatefulWidget {
  4.   @override
  5.   _SplashScreenState createState() => _SplashScreenState();
  6. }
  7.  
  8. class _SplashScreenState extends State<SplashScreen> {
  9.   double opacityLevel = 0.0;
  10.  
  11.   @override
  12.   void initState() {
  13.     super.initState();
  14.  
  15.     // Animasi fading pada elemen gambar
  16.     Future.delayed(Duration(milliseconds: 500), () {
  17.       setState(() {
  18.         opacityLevel = 1.0;
  19.       });
  20.     });
  21.  
  22.     // Navigasi ke halaman home setelah beberapa detik
  23.     Future.delayed(Duration(seconds: 2), () {
  24.       Navigator.pushReplacementNamed(context, '/home');
  25.     });
  26.   }
  27.  
  28.   @override
  29.   Widget build(BuildContext context) {
  30.     return Scaffold(
  31.       appBar: AppBar(),
  32.       body: Center(
  33.         child: Column(
  34.           mainAxisAlignment: MainAxisAlignment.center,
  35.           children: <Widget>[
  36.             Hero(
  37.               tag: 'logo',
  38.               child: AnimatedOpacity(
  39.                 opacity: opacityLevel,
  40.                 duration: Duration(milliseconds: 500),
  41.                 child: ClipOval(
  42.                   child: Image.asset(
  43.                     'images/image_splash.jpeg',
  44.                     width: 100,
  45.                     height: 100,
  46.                     fit: BoxFit.cover,
  47.                   ),
  48.                 ),
  49.               ),
  50.             ),
  51.             SizedBox(height: 16),
  52.             Text(
  53.               'Contact App',
  54.               style: TextStyle(
  55.                 fontSize: 20,
  56.                 fontFamily: 'kranky',
  57.               ),
  58.             ),
  59.           ],
  60.         ),
  61.       ),
  62.     );
  63.   }
  64. }
  65.  

Editor

You can edit this paste and save as new:


File Description
  • splash
  • Paste Code
  • 10 Dec-2023
  • 1.61 Kb
You can Share it: