120 lines
4.0 KiB
Dart
120 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../core/theme.dart';
|
|
import '../../models/user_model.dart';
|
|
import '../../providers/notification_provider.dart';
|
|
import '../atoms/custom_avatar.dart';
|
|
|
|
class HomeHeader extends StatelessWidget {
|
|
final UserModel user;
|
|
|
|
const HomeHeader({
|
|
super.key,
|
|
required this.user,
|
|
});
|
|
|
|
String _getGreeting() {
|
|
final hour = DateTime.now().hour;
|
|
if (hour >= 4 && hour < 11) return "Selamat Pagi ☀️";
|
|
if (hour >= 11 && hour < 15) return "Selamat Siang 🌤️";
|
|
if (hour >= 15 && hour < 18) return "Selamat Sore 🌅";
|
|
return "Selamat Malam 🌙";
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final unreadCount = context.watch<NotificationProvider>().unreadCount;
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
// Avatar Profil tanpa border putih
|
|
CustomAvatar(
|
|
imageUrl: user.foto,
|
|
name: user.namaLengkap,
|
|
size: 48,
|
|
),
|
|
const SizedBox(width: AppTheme.spacingMd),
|
|
|
|
// Greeting & Name dengan teks gelap (menyatu dengan background terang)
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
_getGreeting(),
|
|
style: AppTheme.bodySmall.copyWith(color: AppTheme.textSecondary),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
user.namaLengkap.split(' ').first,
|
|
style: AppTheme.heading2.copyWith(color: AppTheme.textPrimary),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// Notification Button minimalis
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
customBorder: const CircleBorder(),
|
|
onTap: () => Navigator.pushNamed(context, '/notification'),
|
|
child: const Padding(
|
|
padding: EdgeInsets.all(12.0),
|
|
child: Icon(Icons.notifications_none_rounded, color: AppTheme.primaryDark, size: 24),
|
|
),
|
|
),
|
|
),
|
|
if (unreadCount > 0)
|
|
Positioned(
|
|
right: 8,
|
|
top: 8,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFef4444),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
constraints: const BoxConstraints(minWidth: 16, minHeight: 16),
|
|
child: Text(
|
|
unreadCount > 9 ? '9+' : '$unreadCount',
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 10,
|
|
fontWeight: FontWeight.bold,
|
|
height: 1.1,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|