games_app/prediqo_mobile/lib/features/wallet/presentation/dashboard_shell.dart
2026-06-29 15:01:23 +02:00

135 lines
3.9 KiB
Dart

/// Wallet presentation: persistent bottom navigation shell for authenticated routes.
library;
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../core/theme/app_theme.dart';
/// Wraps authenticated main screens (dashboard, deposit, withdraw, etc.) so the
/// bottom navigation bar is always visible and users can switch tabs easily.
class DashboardShell extends StatelessWidget {
const DashboardShell({
super.key,
required this.state,
required this.child,
});
final GoRouterState state;
final Widget child;
/// Which bottom nav index is selected based on current route.
int _selectedIndex() {
final path = state.uri.path;
if (path == '/dashboard') {
final tab = int.tryParse(state.uri.queryParameters['tab'] ?? '0') ?? 0;
return tab.clamp(0, 3);
}
if (path.startsWith('/deposit') || path == '/withdraw' || path == '/transfer' || path == '/transactions') {
return 1; // Wallet
}
if (path.startsWith('/account') || path == '/totp-setup') {
return 2; // Account
}
if (path.startsWith('/options') || path.startsWith('/admin/')) {
return 3; // Options
}
return 0; // Home
}
@override
Widget build(BuildContext context) {
final selected = _selectedIndex();
return Scaffold(
body: child,
bottomNavigationBar: Container(
decoration: const BoxDecoration(
gradient: AppTheme.goldGradient,
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 12,
offset: Offset(0, -4),
),
],
),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_NavItem(
icon: Icons.home_rounded,
label: 'Home',
selected: selected == 0,
onTap: () => context.go('/dashboard?tab=0'),
),
_NavItem(
icon: Icons.account_balance_wallet_rounded,
label: 'Wallet',
selected: selected == 1,
onTap: () => context.go('/dashboard?tab=1'),
),
_NavItem(
icon: Icons.person_rounded,
label: 'Account',
selected: selected == 2,
onTap: () => context.go('/account'),
),
_NavItem(
icon: Icons.settings_rounded,
label: 'Options',
selected: selected == 3,
onTap: () => context.go('/options'),
),
],
),
),
),
),
);
}
}
/// Single bottom navigation item with icon, label, and selected styling.
class _NavItem extends StatelessWidget {
const _NavItem({
required this.icon,
required this.label,
required this.selected,
required this.onTap,
});
final IconData icon;
final String label;
final bool selected;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final color = selected ? AppColors.goldLight : Colors.white70;
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, color: color, size: 26),
const SizedBox(height: 4),
Text(
label,
style: TextStyle(
color: color,
fontSize: 12,
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
),
),
],
),
),
);
}
}