voo_navigation_bar 0.1.5
voo_navigation_bar: ^0.1.5 copied to clipboard
Bottom navigation bar components for Flutter - part of the voo_navigation package ecosystem.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:voo_navigation_bar/voo_navigation_bar.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'VoO Navigation Bar Example',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF10B981)),
useMaterial3: true,
),
home: const BottomNavigationExample(),
);
}
}
class BottomNavigationExample extends StatefulWidget {
const BottomNavigationExample({super.key});
@override
State<BottomNavigationExample> createState() => _BottomNavigationExampleState();
}
class _BottomNavigationExampleState extends State<BottomNavigationExample> {
String _selectedId = 'home';
final List<VooNavigationDestination> _items = const [
VooNavigationDestination(
id: 'home',
label: 'Home',
icon: Icons.home_outlined,
selectedIcon: Icons.home,
route: '/home',
mobilePriority: true,
),
VooNavigationDestination(
id: 'search',
label: 'Search',
icon: Icons.search_outlined,
selectedIcon: Icons.search,
route: '/search',
mobilePriority: true,
),
VooNavigationDestination(
id: 'notifications',
label: 'Alerts',
icon: Icons.notifications_outlined,
selectedIcon: Icons.notifications,
route: '/notifications',
mobilePriority: true,
),
VooNavigationDestination(
id: 'profile',
label: 'Profile',
icon: Icons.person_outlined,
selectedIcon: Icons.person,
route: '/profile',
mobilePriority: true,
),
];
void _onItemSelected(String itemId) {
setState(() {
_selectedId = itemId;
});
}
VooNavigationConfig get _config => VooNavigationConfig(
items: _items,
selectedId: _selectedId,
onNavigationItemSelected: _onItemSelected,
);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
return Scaffold(
appBar: AppBar(
title: const Text('Bottom Navigation Bar'),
backgroundColor: colorScheme.inversePrimary,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
color: const Color(0xFF10B981).withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(20),
),
child: Icon(
_getIconForId(_selectedId),
size: 40,
color: const Color(0xFF10B981),
),
),
const SizedBox(height: 16),
Text(
_getLabelForId(_selectedId),
style: theme.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
'Selected: $_selectedId',
style: theme.textTheme.bodyMedium?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
),
),
bottomNavigationBar: VooNavigationBar(
config: _config,
selectedId: _selectedId,
onNavigationItemSelected: _onItemSelected,
enableFeedback: true,
),
);
}
VooNavigationDestination? _findItemById(String id) {
for (final item in _items) {
if (item.id == id) return item;
}
return null;
}
IconData _getIconForId(String id) {
final item = _findItemById(id) ?? _items.first;
return item.selectedIcon ?? item.icon;
}
String _getLabelForId(String id) {
final item = _findItemById(id) ?? _items.first;
return item.label;
}
}