Files
kent_logistics_app/lib/screens/splash_screen.dart

179 lines
5.4 KiB
Dart
Raw Normal View History

2025-11-28 10:14:30 +05:30
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
2025-12-03 11:57:05 +05:30
import 'main_bottom_nav.dart';
2025-11-28 10:14:30 +05:30
import 'welcome_screen.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
2025-12-03 11:57:05 +05:30
2025-11-28 10:14:30 +05:30
@override
State<SplashScreen> createState() => _SplashScreenState();
}
2025-12-11 18:36:11 +05:30
class _SplashScreenState extends State<SplashScreen>
with TickerProviderStateMixin {
late AnimationController _mainController;
late Animation<double> _scaleAnim;
late Animation<double> _fadeAnim;
late AnimationController _floatController;
late Animation<double> _floatAnim;
2025-11-28 10:14:30 +05:30
@override
void initState() {
super.initState();
2025-12-11 18:36:11 +05:30
// MAIN splash animation
_mainController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1200),
);
_scaleAnim = Tween(begin: 0.6, end: 1.0).animate(
CurvedAnimation(parent: _mainController, curve: Curves.easeOutBack),
);
_fadeAnim = Tween(begin: 0.0, end: 1.0).animate(
CurvedAnimation(parent: _mainController, curve: Curves.easeIn),
);
// FLOATING animation (infinite)
_floatController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)..repeat(reverse: true);
_floatAnim = Tween<double>(begin: -10, end: 10).animate(
CurvedAnimation(parent: _floatController, curve: Curves.easeInOut),
);
_mainController.forward();
2025-11-28 10:14:30 +05:30
_init();
}
2025-12-11 18:36:11 +05:30
Future<void> _init() async {
await Future.delayed(const Duration(milliseconds: 700));
2025-12-03 11:57:05 +05:30
2025-11-28 10:14:30 +05:30
final auth = Provider.of<AuthProvider>(context, listen: false);
2025-12-03 11:57:05 +05:30
await auth.init();
if (!mounted) return;
2025-12-11 18:36:11 +05:30
Future.delayed(const Duration(milliseconds: 900), () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) =>
auth.isLoggedIn ? const MainBottomNav() : const WelcomeScreen(),
),
2025-12-03 11:57:05 +05:30
);
2025-12-11 18:36:11 +05:30
});
}
@override
void dispose() {
_mainController.dispose();
_floatController.dispose();
super.dispose();
2025-11-28 10:14:30 +05:30
}
@override
Widget build(BuildContext context) {
2025-12-11 18:36:11 +05:30
final width = MediaQuery.of(context).size.width;
// Responsive scale factor
final scale = (width / 430).clamp(0.9, 1.3);
2025-11-28 10:14:30 +05:30
return Scaffold(
2025-12-11 18:36:11 +05:30
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.blue.shade50,
Colors.white,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
width: double.infinity,
height: double.infinity,
child: Center(
child: AnimatedBuilder(
animation: _mainController,
builder: (_, __) {
return Opacity(
opacity: _fadeAnim.value,
child: Transform.translate(
offset: Offset(0, _floatAnim.value), // ⭐ Floating animation
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// ⭐ Animated Floating White Circle Logo
Transform.scale(
scale: _scaleAnim.value,
child: AnimatedBuilder(
animation: _floatController,
builder: (_, __) {
return Container(
width: width * 0.50 * scale,
height: width * 0.50 * scale,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black
.withOpacity(0.08 + (_floatAnim.value.abs() / 200)),
blurRadius: 25 * scale,
spreadRadius: 4 * scale,
offset: Offset(0, 8 * scale),
),
],
),
child: Padding(
padding: EdgeInsets.all(28 * scale),
child: Image.asset(
"assets/Images/K.png",
fit: BoxFit.contain,
),
),
);
},
),
),
SizedBox(height: 22 * scale),
Text(
"Kent Logistics",
style: TextStyle(
fontSize: 22 * scale,
fontWeight: FontWeight.w700,
letterSpacing: 1.1,
),
),
SizedBox(height: 6 * scale),
Text(
"Delivering Excellence",
style: TextStyle(
fontSize: 14 * scale,
color: Colors.black54,
),
)
],
),
),
);
},
2025-11-28 10:14:30 +05:30
),
2025-12-11 18:36:11 +05:30
),
2025-11-28 10:14:30 +05:30
),
);
}
}