Files
worker/lib/features/main/presentation/pages/main_scaffold.dart
2025-10-24 14:42:14 +07:00

217 lines
7.2 KiB
Dart

/// Main Scaffold with Bottom Navigation
///
/// Root navigation wrapper that manages the bottom navigation bar
/// and displays different pages based on the selected tab.
library;
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:worker/core/theme/colors.dart';
import 'package:worker/features/home/presentation/pages/home_page.dart';
import 'package:worker/features/main/presentation/providers/current_page_provider.dart';
import 'package:worker/features/promotions/presentation/pages/promotions_page.dart';
/// Main Scaffold Page
///
/// Manages bottom navigation and page switching for:
/// - Home (index 0)
/// - Loyalty (index 1) - Coming soon
/// - Promotions (index 2)
/// - Notifications (index 3) - Coming soon
/// - Account (index 4) - Coming soon
class MainScaffold extends ConsumerWidget {
const MainScaffold({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final currentIndex = ref.watch(currentPageIndexProvider);
// Define pages
final pages = [
const HomePage(),
_buildComingSoonPage('Hội viên'), // Loyalty
const PromotionsPage(),
_buildComingSoonPage('Thông báo'), // Notifications
_buildComingSoonPage('Cài đặt'), // Account
];
return Scaffold(
body: IndexedStack(
index: currentIndex,
children: pages,
),
floatingActionButton: currentIndex == 0
? Padding(
padding: const EdgeInsets.only(bottom: 20),
child: FloatingActionButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Chat - Đang phát triển'),
duration: Duration(seconds: 1),
),
);
},
backgroundColor: AppColors.accentCyan,
elevation: 8,
child: const Icon(Icons.chat_bubble, size: 24, color: Colors.white),
),
)
: null,
bottomNavigationBar: Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, -2),
),
],
),
child: SafeArea(
child: SizedBox(
height: 70,
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.white,
selectedItemColor: AppColors.primaryBlue,
unselectedItemColor: const Color(0xFF666666),
selectedFontSize: 11,
unselectedFontSize: 11,
iconSize: 24,
currentIndex: currentIndex,
elevation: 0,
items: [
const BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Trang chủ',
),
const BottomNavigationBarItem(
icon: Icon(Icons.loyalty),
label: 'Hội viên',
),
const BottomNavigationBarItem(
icon: Icon(Icons.local_offer),
label: 'Khuyến mãi',
),
BottomNavigationBarItem(
icon: Stack(
clipBehavior: Clip.none,
children: [
const Icon(Icons.notifications),
Positioned(
top: -4,
right: -4,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: AppColors.danger,
borderRadius: BorderRadius.circular(12),
),
constraints: const BoxConstraints(
minWidth: 20,
minHeight: 20,
),
child: const Text(
'5',
style: TextStyle(
color: Colors.white,
fontSize: 11,
fontWeight: FontWeight.w700,
),
textAlign: TextAlign.center,
),
),
),
],
),
label: 'Thông báo',
),
const BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: 'Cài đặt',
),
],
onTap: (index) {
ref.read(currentPageIndexProvider.notifier).setIndex(index);
},
),
),
),
),
);
}
/// Build coming soon placeholder page
Widget _buildComingSoonPage(String title) {
return Scaffold(
backgroundColor: const Color(0xFFF4F6F8),
body: SafeArea(
child: Column(
children: [
// Header
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Text(
title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF212121),
),
),
),
// Coming soon content
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.construction,
size: 80,
color: AppColors.grey500.withValues(alpha: 0.5),
),
const SizedBox(height: 16),
const Text(
'Đang phát triển',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: AppColors.grey500,
),
),
const SizedBox(height: 8),
const Text(
'Tính năng này sẽ sớm ra mắt',
style: TextStyle(
fontSize: 14,
color: AppColors.grey500,
),
),
],
),
),
),
],
),
),
);
}
}