From 1b090a43a0648db180f01ebc55debd606bc808f2 Mon Sep 17 00:00:00 2001 From: Yannick <69087944+GelbEinhalb@users.noreply.github.com> Date: Sun, 9 Nov 2025 20:49:14 +0100 Subject: [PATCH] a bit cleaner solution --- .../main_menu/custom_navigation_bar.dart | 32 ++++++++++++++++--- lib/presentation/widgets/navbar_item.dart | 27 ++++++++-------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/lib/presentation/views/main_menu/custom_navigation_bar.dart b/lib/presentation/views/main_menu/custom_navigation_bar.dart index 10ee10f..20ced7a 100644 --- a/lib/presentation/views/main_menu/custom_navigation_bar.dart +++ b/lib/presentation/views/main_menu/custom_navigation_bar.dart @@ -67,10 +67,34 @@ class _CustomNavigationBarState extends State child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - NavbarItem(currentIndex: currentIndex, index: 0, icon: Icons.home_rounded, label: 'Home', onTabTapped: onTabTapped), - NavbarItem(currentIndex: currentIndex, index: 1, icon: Icons.gamepad_rounded, label: 'Games', onTabTapped: onTabTapped), - NavbarItem(currentIndex: currentIndex, index: 2, icon: Icons.group_rounded, label: 'Groups', onTabTapped: onTabTapped), - NavbarItem(currentIndex: currentIndex, index: 3, icon: Icons.bar_chart_rounded, label: 'Stats', onTabTapped: onTabTapped), + NavbarItem( + index: 0, + isSelected: currentIndex == 0, + icon: Icons.home_rounded, + label: 'Home', + onTabTapped: onTabTapped, + ), + NavbarItem( + index: 1, + isSelected: currentIndex == 1, + icon: Icons.gamepad_rounded, + label: 'Games', + onTabTapped: onTabTapped, + ), + NavbarItem( + index: 2, + isSelected: currentIndex == 2, + icon: Icons.group_rounded, + label: 'Groups', + onTabTapped: onTabTapped, + ), + NavbarItem( + index: 3, + isSelected: currentIndex == 3, + icon: Icons.bar_chart_rounded, + label: 'Stats', + onTabTapped: onTabTapped, + ), ], ), ), diff --git a/lib/presentation/widgets/navbar_item.dart b/lib/presentation/widgets/navbar_item.dart index f178ccf..b249571 100644 --- a/lib/presentation/widgets/navbar_item.dart +++ b/lib/presentation/widgets/navbar_item.dart @@ -1,18 +1,20 @@ import 'package:flutter/material.dart'; class NavbarItem extends StatefulWidget { - - final int currentIndex; final int index; + final bool isSelected; final IconData icon; final String label; final Function(int) onTabTapped; - const NavbarItem( - {super.key, required this.currentIndex, required this.index, - required this.icon, required this.label, required this.onTabTapped - } - ); + const NavbarItem({ + super.key, + required this.index, + required this.isSelected, + required this.icon, + required this.label, + required this.onTabTapped, + }); @override State createState() => _NavbarItemState(); @@ -21,9 +23,6 @@ class NavbarItem extends StatefulWidget { class _NavbarItemState extends State { @override Widget build(BuildContext context) { - - bool isSelected = widget.currentIndex == widget.index; - return Expanded( child: GestureDetector( onTap: () => widget.onTabTapped(widget.index), @@ -36,15 +35,17 @@ class _NavbarItemState extends State { children: [ Icon( widget.icon, - color: isSelected ? Colors.white : Colors.black, + color: widget.isSelected ? Colors.white : Colors.black, ), const SizedBox(height: 4), Text( widget.label, style: TextStyle( - color: isSelected ? Colors.white : Colors.black, + color: widget.isSelected ? Colors.white : Colors.black, fontSize: 12, - fontWeight: isSelected ? FontWeight.bold : FontWeight.normal, + fontWeight: widget.isSelected + ? FontWeight.bold + : FontWeight.normal, ), ), ],