Files
voidea/flutter/lib/widgets/shell.dart
T

83 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_animate/flutter_animate.dart';
import '../providers/notification_provider.dart';
import '../core/constants/app_constants.dart';
class Shell extends ConsumerWidget {
final Widget child;
const Shell({super.key, required this.child});
@override
Widget build(BuildContext context, WidgetRef ref) {
final unreadCount = ref.watch(unreadCountProvider);
final colorScheme = Theme.of(context).colorScheme;
final currentLocation = GoRouterState.of(context).matchedLocation;
int currentIndex = _navIndex(currentLocation);
return Scaffold(
body: child,
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
onTap: (index) => _onTap(context, index),
items: [
const BottomNavigationBarItem(
icon: Icon(Icons.dashboard_outlined),
activeIcon: Icon(Icons.dashboard),
label: 'Дашборд',
),
const BottomNavigationBarItem(
icon: Icon(Icons.lightbulb_outline),
activeIcon: Icon(Icons.lightbulb),
label: 'Идеи',
),
const BottomNavigationBarItem(
icon: Icon(Icons.mic_outlined),
activeIcon: Icon(Icons.mic),
label: 'Голос',
),
const BottomNavigationBarItem(
icon: Icon(Icons.notifications_outlined),
activeIcon: Icon(Icons.notifications),
label: 'Уведомления',
),
const BottomNavigationBarItem(
icon: Icon(Icons.settings_outlined),
activeIcon: Icon(Icons.settings),
label: 'Настройки',
),
],
),
).animate().fadeIn(duration: 200.ms);
}
int _navIndex(String location) {
if (location.startsWith('/ideas')) return 1;
if (location.startsWith('/voice')) return 2;
if (location.startsWith('/notifications')) return 3;
if (location.startsWith('/settings') ||
location.startsWith('/admin') ||
location.startsWith('/workspaces')) return 4;
return 0;
}
void _onTap(BuildContext context, int index) {
switch (index) {
case 0:
context.go('/');
case 1:
context.go('/ideas');
case 2:
context.go('/voice');
case 3:
context.go('/notifications');
case 4:
context.go('/settings');
}
}
}