Pada kali ini kita akan membuat sebuah tampilan SplashScreen pada Flutter. SplashScreen merupakan tampilan awal ketika menjalankan sebuah project. Cara membuat SplashScreen yaitu:
- Buatlah sebuah project baru pada flutter
- Buatlah sebuah function dan inistate() pada flutter
void splashScreen(){
Timer(Duration(seconds: 3), () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => LoginPage()));
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
splashScreen();
}
- Buatlah tampilan splashscreen sesuai dengan keinginan anda
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Spacer(),
Center(
child: Image.asset("assets/images/logo.png", scale: 12),
),
Spacer(),
Text(
"Medical Center",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 20,
fontFamily: "Poppins"
),
),
],
),
- Full source code
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:splashscreen/login.dart';
class SplashWidget extends StatefulWidget {
const SplashWidget({Key? key}) : super(key: key);
@override
State<SplashWidget> createState() => _SplashWidgetState();
}
class _SplashWidgetState extends State<SplashWidget> {
void splashScreen(){
Timer(Duration(seconds: 3), () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => LoginPage()));
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
splashScreen();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Spacer(),
Center(
child: Image.asset("assets/images/logo.png", scale: 12),
),
Spacer(),
Text(
"Medical Center",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 20,
fontFamily: "Poppins"
),
),
],
),
);
}
}