Last active
April 16, 2022 08:33
-
-
Save triyono777/f62637290c8d6bcfef5e6e896e58f57a 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_satu/list_screen.dart'; | |
import 'package:projek_satu/login_screen.dart'; | |
import 'package:projek_satu/welcome_screen.dart'; | |
import 'home_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: 2); | |
return Timer(duration, () async { | |
var box = Hive.box('userBox'); | |
bool? isLogin = box.get('isLogin'); | |
if (isLogin ?? false){ | |
Navigator.of(context).pushReplacement( | |
MaterialPageRoute(builder: (_) => HomeScreen()), | |
); | |
}else{ | |
Navigator.of(context).pushReplacement( | |
MaterialPageRoute(builder: (_) => WelcomeScreen()), | |
); | |
} | |
}); | |
} | |
@override | |
void initState() { | |
startTimer(); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Image.asset('images/udb.png'), | |
CircularProgressIndicator(), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment