Skip to content

Instantly share code, notes, and snippets.

@JosephineAkello
Created May 24, 2024 13:15
Show Gist options
  • Save JosephineAkello/500999f478ea074ea440ed7f4d5582ac to your computer and use it in GitHub Desktop.
Save JosephineAkello/500999f478ea074ea440ed7f4d5582ac to your computer and use it in GitHub Desktop.
Splash screen page including loading duration and navigating to next Page
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
import 'package:lottie_flutter/home_screen.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
loadSplash();
}
// Load the splash screen for some duration
Future<Timer> loadSplash() async {
return Timer(
const Duration(seconds: 3),
onDoneLoading,
);
}
onDoneLoading() {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: ((context) => const HomeScreenPage()),
),
);
}
@override
Widget build(BuildContext context) {
return Center(
child: Lottie.asset(
"assets/animations/loginAnim.json",
// Can add other properties on how you would like the anim to display
fit: BoxFit.cover,
width: 300,
height: 300,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment