Created
April 18, 2022 04:35
-
-
Save triyono777/d6ee87fe94a50201de1dd674cc70e5b4 to your computer and use it in GitHub Desktop.
This file contains 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 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:hive_flutter/hive_flutter.dart'; | |
import 'package:projek_kel_1/home_screen.dart'; | |
import 'login_screen.dart'; | |
class SplashScreen extends StatefulWidget { | |
const SplashScreen({Key? key}) : super(key: key); | |
@override | |
State<SplashScreen> createState() => _SplashScreenState(); | |
} | |
class _SplashScreenState extends State<SplashScreen> { | |
startTimer() async { | |
var duration = Duration(seconds: 5); | |
return Timer(duration, () async { | |
var box = Hive.box('userBox'); | |
bool? sudahLogin = box.get('isLogin'); | |
if(sudahLogin ?? false){ | |
Navigator.of(context).pushReplacement( | |
MaterialPageRoute(builder: (_) => HomeScreen()), | |
); | |
}else{ | |
Navigator.of(context).pushReplacement( | |
MaterialPageRoute(builder: (_) => LoginScreen()), | |
); | |
} | |
}); | |
} | |
@override | |
void initState() { | |
startTimer(); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Image.asset('assets/images/udb.png'), | |
CircularProgressIndicator(), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment