[dart] d

Viewer

  1. // splash_screen.dart
  2. import 'package:flutter/material.dart';
  3. import 'dart:async';
  4. import 'home_screen.dart';
  5.  
  6. class SplashScreen extends StatefulWidget {
  7.   @override
  8.   _SplashScreenState createState() => _SplashScreenState();
  9. }
  10.  
  11. class _SplashScreenState extends State<SplashScreen> {
  12.   double logoOpacity = 0.0; // Mulai dengan opasitas 0.0
  13.   double textOpacity = 0.0; // Mulai dengan opasitas 0.0
  14.  
  15.   @override
  16.   void initState() {
  17.     super.initState();
  18.  
  19.     // Menjalankan animasi opasitas setelah 1 detik
  20.     Timer(
  21.       Duration(seconds: 1),
  22.       () {
  23.         setState(() {
  24.           logoOpacity = 1.0; // Setelah 1 detik, ubah opasitas logo menjadi 1.0
  25.           textOpacity = 1.0; // Setelah 1 detik, ubah opasitas teks menjadi 1.0
  26.         });
  27.  
  28.         // Setelah muncul dengan jelas, jalankan animasi kedip
  29.         startBlinkAnimation();
  30.       },
  31.     );
  32.  
  33.     // Pindah ke halaman beranda setelah 8 detik (3 detik untuk muncul dengan jelas + 5 detik untuk 3 kali kedip)
  34.     Timer(
  35.       Duration(seconds: 8),
  36.       () {
  37.         Navigator.of(context).pushReplacement(
  38.           MaterialPageRoute(
  39.             builder: (BuildContext context) => HomeScreen(),
  40.           ),
  41.         );
  42.       },
  43.     );
  44.   }
  45.  
  46.   void startBlinkAnimation() {
  47.     const int totalBlinks = 3;
  48.  
  49.     for (int i = 0; i < totalBlinks; i++) {
  50.       Timer(
  51.         Duration(
  52.             seconds: 1 *
  53.                 (+ 2)), // Menjadwalkan kedipan setelah muncul dengan jelas
  54.         () {
  55.           setState(() {
  56.             logoOpacity =
  57.                 1.0 - logoOpacity; // Toggle opasitas antara 0.0 dan 1.0
  58.           });
  59.         },
  60.       );
  61.     }
  62.  
  63.     // Setelah 3 kali kedip, jalankan animasi menghilang
  64.     Timer(
  65.       Duration(seconds: 1 * (totalBlinks + 2)),
  66.       () {
  67.         setState(() {
  68.           logoOpacity =
  69.               0.0; // Setelah 3 kali kedip, ubah opasitas logo menjadi 0.0
  70.           textOpacity =
  71.               0.0; // Setelah 3 kali kedip, ubah opasitas teks menjadi 0.0
  72.         });
  73.       },
  74.     );
  75.   }
  76.  
  77.   @override
  78.   Widget build(BuildContext context) {
  79.     return Scaffold(
  80.       body: Center(
  81.         child: Column(
  82.           mainAxisAlignment: MainAxisAlignment.center,
  83.           children: [
  84.             AnimatedOpacity(
  85.               opacity: logoOpacity,
  86.               duration: Duration(seconds: 2),
  87.               child:
  88.                   Image.asset('image/logo.png', width: 230.0, height: 230.0),
  89.             ),
  90.             SizedBox(height: 16.0), // Jarak antara gambar dan teks
  91.             AnimatedOpacity(
  92.               opacity: textOpacity,
  93.               duration: Duration(seconds: 2),
  94.               child: Text(
  95.                 'Contact Me',
  96.                 style: TextStyle(
  97.                   fontSize: 24.0,
  98.                   fontWeight: FontWeight.bold,
  99.                 ),
  100.               ),
  101.             ),
  102.           ],
  103.         ),
  104.       ),
  105.     );
  106.   }
  107. }

Editor

You can edit this paste and save as new:


File Description
  • d
  • Paste Code
  • 10 Dec-2023
  • 2.91 Kb
You can Share it: