113 lines
3.0 KiB
Dart
113 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:gif_view/gif_view.dart';
|
|
|
|
class SplashScreen extends StatefulWidget {
|
|
final VoidCallback onSplashComplete;
|
|
|
|
const SplashScreen({super.key, required this.onSplashComplete});
|
|
|
|
@override
|
|
State<SplashScreen> createState() => _SplashScreenState();
|
|
}
|
|
|
|
class _SplashScreenState extends State<SplashScreen>
|
|
with TickerProviderStateMixin {
|
|
late AnimationController _fadeController;
|
|
late AnimationController _scaleController;
|
|
late Animation<double> _fadeAnimation;
|
|
late Animation<double> _scaleAnimation;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// Initialize animation controllers
|
|
_fadeController = AnimationController(
|
|
duration: const Duration(milliseconds: 1000),
|
|
vsync: this,
|
|
);
|
|
|
|
_scaleController = AnimationController(
|
|
duration: const Duration(milliseconds: 800),
|
|
vsync: this,
|
|
);
|
|
|
|
// Create animations
|
|
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
|
CurvedAnimation(parent: _fadeController, curve: Curves.easeInOut),
|
|
);
|
|
|
|
_scaleAnimation = Tween<double>(begin: 0.8, end: 1.0).animate(
|
|
CurvedAnimation(parent: _scaleController, curve: Curves.elasticOut),
|
|
);
|
|
|
|
// Start animations
|
|
_startAnimations();
|
|
}
|
|
|
|
void _startAnimations() async {
|
|
try {
|
|
// Start fade in and scale animations
|
|
_fadeController.forward();
|
|
_scaleController.forward();
|
|
|
|
// Wait for 3 seconds (adjust as needed)
|
|
await Future.delayed(const Duration(milliseconds: 1250));
|
|
|
|
// Start fade out animation
|
|
await _fadeController.reverse();
|
|
|
|
// Call the completion callback
|
|
if (mounted) {
|
|
widget.onSplashComplete();
|
|
}
|
|
} catch (e) {
|
|
// If there's an error, still complete the splash screen
|
|
if (mounted) {
|
|
widget.onSplashComplete();
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_fadeController.dispose();
|
|
_scaleController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
body: AnimatedBuilder(
|
|
animation: Listenable.merge([_fadeController, _scaleController]),
|
|
builder: (context, child) {
|
|
return FadeTransition(
|
|
opacity: _fadeAnimation,
|
|
child: ScaleTransition(
|
|
scale: _scaleAnimation,
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: MediaQuery.of(context).size.height,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(20),
|
|
child: GifView.asset(
|
|
'assets/giphy.gif',
|
|
width: MediaQuery.of(context).size.width,
|
|
height: MediaQuery.of(context).size.height,
|
|
frameRate: 30,
|
|
fit: BoxFit.contain,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|