You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
5.0 KiB
177 lines
5.0 KiB
// ignore_for_file: deprecated_member_use, duplicate_ignore
|
|
|
|
import 'package:flutter/material.dart';
|
|
import '../home/home_screen.dart';
|
|
import '../recipes/recipes_screen.dart';
|
|
import '../favourites/favourites_screen.dart';
|
|
import '../session/session_screen.dart';
|
|
import 'app_router.dart';
|
|
|
|
/// Main navigation scaffold with bottom navigation bar and centered Add button.
|
|
class MainNavigationScaffold extends StatefulWidget {
|
|
const MainNavigationScaffold({super.key});
|
|
|
|
@override
|
|
State<MainNavigationScaffold> createState() => _MainNavigationScaffoldState();
|
|
}
|
|
|
|
class _MainNavigationScaffoldState extends State<MainNavigationScaffold> {
|
|
int _currentIndex = 0;
|
|
|
|
void _onItemTapped(int index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
}
|
|
|
|
void _onAddRecipePressed(BuildContext context) {
|
|
Navigator.pushNamed(context, AppRoutes.addRecipe);
|
|
}
|
|
|
|
Widget _buildScreen(int index) {
|
|
switch (index) {
|
|
case 0:
|
|
return const HomeScreen();
|
|
case 1:
|
|
return const RecipesScreen();
|
|
case 2:
|
|
return const FavouritesScreen();
|
|
case 3:
|
|
return const SessionScreen();
|
|
default:
|
|
return const SizedBox();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: IndexedStack(
|
|
index: _currentIndex,
|
|
children: List.generate(4, (index) => _buildScreen(index)),
|
|
),
|
|
bottomNavigationBar: _buildCustomBottomNav(context),
|
|
);
|
|
}
|
|
|
|
Widget _buildCustomBottomNav(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).bottomNavigationBarTheme.backgroundColor ??
|
|
Theme.of(context).scaffoldBackgroundColor,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.1),
|
|
blurRadius: 4,
|
|
offset: const Offset(0, -2),
|
|
),
|
|
],
|
|
),
|
|
child: SafeArea(
|
|
child: Container(
|
|
height: kBottomNavigationBarHeight,
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
// Home
|
|
_buildNavItem(
|
|
icon: Icons.home,
|
|
label: 'Home',
|
|
index: 0,
|
|
onTap: () => _onItemTapped(0),
|
|
),
|
|
// Recipes
|
|
_buildNavItem(
|
|
icon: Icons.menu_book,
|
|
label: 'Recipes',
|
|
index: 1,
|
|
onTap: () => _onItemTapped(1),
|
|
),
|
|
// Center Add Recipe button
|
|
Container(
|
|
width: 56,
|
|
height: 56,
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
child: Material(
|
|
color: Theme.of(context).primaryColor,
|
|
shape: const CircleBorder(),
|
|
child: InkWell(
|
|
onTap: () => _onAddRecipePressed(context),
|
|
customBorder: const CircleBorder(),
|
|
child: const Icon(
|
|
Icons.add,
|
|
color: Colors.white,
|
|
size: 28,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
// Favourites
|
|
_buildNavItem(
|
|
icon: Icons.favorite,
|
|
label: 'Favourites',
|
|
index: 2,
|
|
onTap: () => _onItemTapped(2),
|
|
),
|
|
// User
|
|
_buildNavItem(
|
|
icon: Icons.person,
|
|
label: 'User',
|
|
index: 3,
|
|
onTap: () => _onItemTapped(3),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildNavItem({
|
|
required IconData icon,
|
|
required String label,
|
|
required int index,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
final isSelected = _currentIndex == index;
|
|
return Expanded(
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
icon,
|
|
color: isSelected
|
|
? Theme.of(context).primaryColor
|
|
: Theme.of(context).iconTheme.color?.withOpacity(0.6),
|
|
size: 24,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: isSelected
|
|
? Theme.of(context).primaryColor
|
|
// ignore: deprecated_member_use
|
|
: Theme.of(context)
|
|
.textTheme
|
|
.bodySmall
|
|
?.color
|
|
?.withOpacity(0.6),
|
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|