generateSplashScreen static method
Generates a splash screen
Implementation
static String generateSplashScreen(String projectName) {
return '''
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:$projectName/core/services/feature_service.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _fadeAnimation;
late Animation<double> _scaleAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 1500),
vsync: this,
);
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeIn),
);
_scaleAnimation = Tween<double>(begin: 0.5, end: 1.0).animate(
CurvedAnimation(parent: _controller, curve: Curves.elasticOut),
);
_controller.forward();
_navigateToNextScreen();
}
Future<void> _navigateToNextScreen() async {
await Future.delayed(const Duration(seconds: 3));
if (mounted) {
// Check if user has completed onboarding
final onboardingCompleted = await FeatureService.isOnboardingCompleted();
if (onboardingCompleted) {
context.go('/');
} else {
context.go('/onboarding');
}
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDark
? [
theme.colorScheme.surface,
theme.colorScheme.surface.withOpacity(0.8),
]
: [
theme.colorScheme.primary.withOpacity(0.1),
theme.colorScheme.secondary.withOpacity(0.1),
],
),
),
child: Center(
child: FadeTransition(
opacity: _fadeAnimation,
child: ScaleTransition(
scale: _scaleAnimation,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(32),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
theme.colorScheme.primary,
theme.colorScheme.secondary,
],
),
boxShadow: [
BoxShadow(
color: theme.colorScheme.primary.withOpacity(0.4),
blurRadius: 30,
spreadRadius: 5,
),
],
),
child: Icon(
Icons.rocket_launch_rounded,
size: 80,
color: Colors.white,
),
),
const SizedBox(height: 40),
Text(
'$projectName',
style: theme.textTheme.displayMedium?.copyWith(
fontWeight: FontWeight.bold,
letterSpacing: 1,
),
),
const SizedBox(height: 12),
Text(
'Welcome to Your App',
style: theme.textTheme.titleMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
),
const SizedBox(height: 60),
SizedBox(
width: 50,
height: 50,
child: CircularProgressIndicator(
strokeWidth: 3,
valueColor: AlwaysStoppedAnimation<Color>(
theme.colorScheme.primary,
),
),
),
],
),
),
),
),
),
);
}
}
''';
}