import 'package:flutter/material.dart'; class LoadingContent extends StatefulWidget { final Future Function()? onBackgroundTask; final String? loadingText; final VoidCallback? onComplete; const LoadingContent({ Key? key, this.onBackgroundTask, this.loadingText = "Chargement en cours...", this.onComplete, }) : super(key: key); @override State createState() => _LoadingContentState(); } class _LoadingContentState extends State with TickerProviderStateMixin { late AnimationController _rotationController; late AnimationController _pulseController; late Animation _rotationAnimation; late Animation _pulseAnimation; @override void initState() { super.initState(); _rotationController = AnimationController( duration: const Duration(seconds: 2), vsync: this, )..repeat(); _pulseController = AnimationController( duration: const Duration(milliseconds: 1500), vsync: this, )..repeat(reverse: true); _rotationAnimation = Tween( begin: 0, end: 1, ).animate(_rotationController); _pulseAnimation = Tween(begin: 0.8, end: 1.2).animate( CurvedAnimation(parent: _pulseController, curve: Curves.easeInOut), ); _executeBackgroundTask(); } Future _executeBackgroundTask() async { if (widget.onBackgroundTask != null) { try { await widget.onBackgroundTask!(); if (widget.onComplete != null) { widget.onComplete!(); } } catch (e) { // Gérer les erreurs si nécessaire print('Erreur lors de la tâche en arrière-plan: $e'); } } } @override void dispose() { _rotationController.dispose(); _pulseController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // Animation de rotation et pulsation AnimatedBuilder( animation: Listenable.merge([ _rotationAnimation, _pulseAnimation, ]), builder: (context, child) { return Transform.scale( scale: _pulseAnimation.value, child: RotationTransition( turns: _rotationAnimation, child: Container( width: 80, height: 80, decoration: BoxDecoration( shape: BoxShape.circle, gradient: LinearGradient( colors: [ Colors.blue.shade400, Colors.purple.shade400, ], begin: Alignment.topLeft, end: Alignment.bottomRight, ), boxShadow: [ BoxShadow( color: Colors.blue.withOpacity(0.3), blurRadius: 20, spreadRadius: 5, ), ], ), child: const Icon( Icons.travel_explore, color: Colors.white, size: 40, ), ), ), ); }, ), const SizedBox(height: 40), // Texte de chargement avec animation AnimatedBuilder( animation: _pulseController, builder: (context, child) { return Opacity( opacity: _pulseAnimation.value - 0.3, child: Text( widget.loadingText ?? "Chargement en cours...", style: TextStyle( fontSize: 18, fontWeight: FontWeight.w500, color: Colors.grey.shade700, ), textAlign: TextAlign.center, ), ); }, ), const SizedBox(height: 20), // Indicateur de progression linéaire SizedBox( width: 200, child: LinearProgressIndicator( backgroundColor: Colors.grey.shade300, valueColor: AlwaysStoppedAnimation(Colors.blue.shade400), ), ), ], ), ), ); } }