491 lines
17 KiB
Dart
Raw Normal View History

2025-08-12 20:44:27 +07:00
import 'package:flutter/material.dart';
2025-08-16 19:56:45 +07:00
import 'package:flutter_bloc/flutter_bloc.dart';
2025-08-16 00:45:05 +07:00
import 'dart:math' as math;
2025-08-12 20:44:27 +07:00
2025-08-16 19:56:45 +07:00
import '../../../../application/auth/auth_bloc.dart';
import '../../../../common/constant/app_constant.dart';
2025-08-13 01:17:00 +07:00
import '../../../../common/extension/extension.dart';
2025-08-16 00:45:05 +07:00
import '../../../../common/painter/wave_painter.dart';
2025-08-12 20:44:27 +07:00
import '../../../../common/theme/theme.dart';
2025-08-16 19:56:45 +07:00
import '../../../../domain/auth/auth.dart';
2025-08-12 20:44:27 +07:00
import '../../../components/spacer/spacer.dart';
2025-08-15 23:59:07 +07:00
class HomeHeader extends StatefulWidget {
2025-08-19 12:23:53 +07:00
final int totalRevenue;
const HomeHeader({super.key, required this.totalRevenue});
2025-08-12 20:44:27 +07:00
2025-08-15 23:59:07 +07:00
@override
State<HomeHeader> createState() => _HomeHeaderState();
}
class _HomeHeaderState extends State<HomeHeader> with TickerProviderStateMixin {
2025-08-16 00:45:05 +07:00
late AnimationController _animationController;
late AnimationController _particleController;
late AnimationController _waveController;
late AnimationController _breathController;
2025-08-15 23:59:07 +07:00
2025-08-16 00:45:05 +07:00
late Animation<double> _fadeInAnimation;
late Animation<Offset> _slideAnimation;
late Animation<double> _scaleAnimation;
late Animation<double> _particleAnimation;
late Animation<double> _waveAnimation;
late Animation<double> _breathAnimation;
2025-08-15 23:59:07 +07:00
@override
void initState() {
super.initState();
2025-08-16 00:45:05 +07:00
// Main content animations
_animationController = AnimationController(
duration: const Duration(milliseconds: 1200),
2025-08-15 23:59:07 +07:00
vsync: this,
2025-08-16 00:45:05 +07:00
);
2025-08-15 23:59:07 +07:00
2025-08-16 00:45:05 +07:00
_particleController = AnimationController(
duration: const Duration(seconds: 8),
2025-08-15 23:59:07 +07:00
vsync: this,
2025-08-16 00:45:05 +07:00
)..repeat();
2025-08-15 23:59:07 +07:00
2025-08-16 00:45:05 +07:00
_waveController = AnimationController(
duration: const Duration(seconds: 6),
2025-08-15 23:59:07 +07:00
vsync: this,
)..repeat();
2025-08-16 00:45:05 +07:00
_breathController = AnimationController(
duration: const Duration(seconds: 4),
vsync: this,
)..repeat(reverse: true);
// Content animations
_fadeInAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _animationController,
curve: const Interval(0.0, 0.6, curve: Curves.easeOut),
),
);
_slideAnimation =
Tween<Offset>(begin: const Offset(0, 0.5), end: Offset.zero).animate(
2025-08-15 23:59:07 +07:00
CurvedAnimation(
2025-08-16 00:45:05 +07:00
parent: _animationController,
curve: const Interval(0.2, 0.8, curve: Curves.easeOutCubic),
2025-08-15 23:59:07 +07:00
),
);
2025-08-16 00:45:05 +07:00
_scaleAnimation = Tween<double>(begin: 0.8, end: 1.0).animate(
2025-08-15 23:59:07 +07:00
CurvedAnimation(
2025-08-16 00:45:05 +07:00
parent: _animationController,
curve: const Interval(0.0, 0.7, curve: Curves.elasticOut),
2025-08-15 23:59:07 +07:00
),
);
2025-08-16 00:45:05 +07:00
_particleAnimation = Tween<double>(
begin: 0.0,
end: 2 * math.pi,
).animate(_particleController);
_waveAnimation = Tween<double>(
begin: 0.0,
end: 2 * math.pi,
).animate(_waveController);
_breathAnimation = Tween<double>(begin: 0.8, end: 1.2).animate(
CurvedAnimation(parent: _breathController, curve: Curves.easeInOut),
2025-08-15 23:59:07 +07:00
);
2025-08-16 00:45:05 +07:00
_animationController.forward();
2025-08-15 23:59:07 +07:00
}
@override
void dispose() {
2025-08-16 00:45:05 +07:00
_animationController.dispose();
_particleController.dispose();
_waveController.dispose();
_breathController.dispose();
2025-08-15 23:59:07 +07:00
super.dispose();
}
2025-08-12 20:44:27 +07:00
@override
Widget build(BuildContext context) {
2025-08-16 19:56:45 +07:00
return BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
return AnimatedBuilder(
animation: Listenable.merge([
_particleController,
_waveController,
_breathController,
]),
builder: (context, child) {
return Container(
height: 280,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
AppColor.primary,
AppColor.primaryLight,
AppColor.primaryLight.withOpacity(0.8),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: const [0.0, 0.7, 1.0],
),
boxShadow: [
BoxShadow(
color: AppColor.primary.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 10),
),
],
2025-08-16 00:45:05 +07:00
),
2025-08-16 19:56:45 +07:00
child: Stack(
children: [
// Enhanced animated background
_buildAnimatedBackground(),
// Main content
SafeArea(child: _buildContent(context, state.user)),
],
),
);
},
2025-08-16 00:45:05 +07:00
);
},
);
}
Widget _buildAnimatedBackground() {
return Stack(
children: [
// Floating particles with orbital motion
...List.generate(12, (index) {
final double radius = 60 + (index * 15);
final double angle = _particleAnimation.value + (index * 0.5);
final double centerX = MediaQuery.of(context).size.width * 0.8;
final double centerY = 100;
2025-08-15 23:59:07 +07:00
2025-08-16 00:45:05 +07:00
return Positioned(
left: centerX + math.cos(angle) * radius - 4,
top: centerY + math.sin(angle) * (radius * 0.5) - 4,
child: Transform.scale(
scale: _breathAnimation.value * 0.4,
child: Container(
width: 2 + (index % 3),
height: 2 + (index % 3),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColor.white.withOpacity(0.7),
boxShadow: [
BoxShadow(
color: AppColor.white.withOpacity(0.3),
blurRadius: 6,
spreadRadius: 1,
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
],
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
),
),
);
}),
// Wave patterns
Positioned.fill(
child: CustomPaint(
painter: WavePainter(
animation: _waveAnimation.value,
color: AppColor.white.withOpacity(0.08),
),
2025-08-12 20:44:27 +07:00
),
2025-08-16 00:45:05 +07:00
),
2025-08-15 23:59:07 +07:00
2025-08-16 00:45:05 +07:00
// Sparkle effects
...List.generate(8, (index) {
return Positioned(
left: (index * 60.0) % MediaQuery.of(context).size.width,
top: 30 + (index * 25.0),
child: Transform.rotate(
angle: _particleAnimation.value * 2 + index,
child: Transform.scale(
scale: math.sin(_particleAnimation.value + index) * 0.3 + 0.8,
child: Icon(
Icons.auto_awesome,
size: 8 + (index % 3) * 3,
color: AppColor.white.withOpacity(0.5),
),
),
),
);
}),
// Gradient overlay for depth
Container(
decoration: BoxDecoration(
gradient: RadialGradient(
center: const Alignment(0.8, -0.3),
radius: 1.5,
colors: [
Colors.transparent,
AppColor.primary.withOpacity(0.1),
Colors.transparent,
],
),
),
),
// Additional left side particles
...List.generate(6, (index) {
final double radius = 40 + (index * 10);
final double angle = _particleAnimation.value * 0.5 + (index * 1.2);
final double centerX = MediaQuery.of(context).size.width * 0.1;
final double centerY = 120;
return Positioned(
left: centerX + math.cos(angle) * radius - 2,
top: centerY + math.sin(angle) * (radius * 0.7) - 2,
child: Transform.scale(
scale: _breathAnimation.value * 0.3 + 0.5,
child: Container(
width: 2 + (index % 2),
height: 2 + (index % 2),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColor.white.withOpacity(0.4),
boxShadow: [
BoxShadow(
color: AppColor.white.withOpacity(0.2),
blurRadius: 4,
),
],
),
),
),
);
}),
],
2025-08-12 20:44:27 +07:00
);
}
2025-08-16 19:56:45 +07:00
Widget _buildContent(BuildContext context, User user) {
2025-08-13 01:17:00 +07:00
String greeting(BuildContext context) {
final hour = DateTime.now().hour;
if (hour >= 4 && hour < 10) {
return context.lang.good_morning;
} else if (hour >= 10 && hour < 15) {
return context.lang.good_afternoon;
} else if (hour >= 15 && hour < 18) {
return context.lang.good_evening;
} else {
return context.lang.good_night;
}
}
2025-08-12 20:44:27 +07:00
return Padding(
padding: EdgeInsets.all(AppValue.padding),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
2025-08-16 00:45:05 +07:00
// Top bar with enhanced animation
SlideTransition(
position: _slideAnimation,
child: FadeTransition(
opacity: _fadeInAnimation,
child: Transform.scale(
scale: _scaleAnimation.value,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2025-08-16 19:56:45 +07:00
AppConstant.appName,
2025-08-16 00:45:05 +07:00
style: AppStyle.lg.copyWith(
color: AppColor.white.withOpacity(0.9),
fontWeight: FontWeight.w600,
letterSpacing: 0.3,
shadows: [
Shadow(
color: Colors.black.withOpacity(0.2),
offset: const Offset(0, 1),
blurRadius: 2,
),
],
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
),
const SpaceHeight(2),
Text(
2025-08-16 19:56:45 +07:00
user.role.toTitleCase,
2025-08-16 00:45:05 +07:00
style: AppStyle.sm.copyWith(
color: AppColor.white.withOpacity(0.7),
fontSize: 11,
fontWeight: FontWeight.w400,
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
),
],
2025-08-12 20:44:27 +07:00
),
2025-08-16 00:45:05 +07:00
),
// Enhanced notification icon with breathing animation
AnimatedBuilder(
animation: _breathController,
builder: (context, child) {
return Transform.scale(
scale: _breathAnimation.value * 0.1 + 1.0,
child: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: AppColor.white.withOpacity(0.25),
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: AppColor.white.withOpacity(0.3),
width: 1,
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
boxShadow: [
BoxShadow(
color: AppColor.white.withOpacity(0.2),
blurRadius: 8 + (_breathAnimation.value * 2),
offset: const Offset(0, 2),
),
],
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
child: const Icon(
Icons.notifications_none_rounded,
color: AppColor.white,
size: 20,
),
),
);
},
),
],
2025-08-12 20:44:27 +07:00
),
2025-08-16 00:45:05 +07:00
),
),
2025-08-12 20:44:27 +07:00
),
const SpaceHeight(24),
2025-08-16 00:45:05 +07:00
// Greeting Section with enhanced animations
SlideTransition(
position: _slideAnimation,
child: FadeTransition(
opacity: _fadeInAnimation,
child: Transform.scale(
scale: _scaleAnimation.value,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${greeting(context)},',
style: AppStyle.lg.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w500,
shadows: [
Shadow(
color: Colors.black.withOpacity(0.2),
offset: const Offset(0, 1),
blurRadius: 2,
),
],
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
),
const SpaceHeight(2),
Text(
2025-08-16 19:56:45 +07:00
'${user.name}! 👋',
2025-08-16 00:45:05 +07:00
style: AppStyle.h4.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w800,
letterSpacing: -0.5,
shadows: [
Shadow(
color: Colors.black.withOpacity(0.2),
offset: const Offset(0, 2),
blurRadius: 4,
),
],
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
),
const SpaceHeight(8),
Text(
context.lang.home_header_desc,
style: AppStyle.md.copyWith(
color: AppColor.white.withOpacity(0.85),
fontWeight: FontWeight.w400,
height: 1.3,
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
),
),
2025-08-12 20:44:27 +07:00
),
const SpaceHeight(16),
2025-08-16 00:45:05 +07:00
// Today's highlight with enhanced breathing animation
FadeTransition(
opacity: _fadeInAnimation,
child: SlideTransition(
position: _slideAnimation,
child: AnimatedBuilder(
animation: _breathController,
builder: (context, child) {
return Transform.scale(
scale: _breathAnimation.value * 0.05 + 1.0,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
decoration: BoxDecoration(
color: AppColor.white.withOpacity(0.25),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: AppColor.white.withOpacity(0.3),
width: 1,
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
boxShadow: [
BoxShadow(
color: AppColor.white.withOpacity(0.1),
blurRadius: 6 + (_breathAnimation.value * 2),
offset: const Offset(0, 2),
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Transform.scale(
scale: _breathAnimation.value * 0.1 + 1.0,
child: Icon(
2025-08-15 23:59:07 +07:00
Icons.trending_up_rounded,
color: AppColor.white,
size: 14,
),
2025-08-16 00:45:05 +07:00
),
const SizedBox(width: 6),
Text(
2025-08-19 12:23:53 +07:00
'${context.lang.sales_today} ${widget.totalRevenue.currencyFormatRp}',
2025-08-16 00:45:05 +07:00
style: AppStyle.sm.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w600,
letterSpacing: 0.3,
2025-08-15 23:59:07 +07:00
),
2025-08-16 00:45:05 +07:00
),
],
),
),
);
},
),
),
2025-08-12 20:44:27 +07:00
),
],
),
);
}
}