Navbar Anpassen #9
@@ -67,10 +67,34 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
NavbarItem(currentIndex: currentIndex, index: 0, icon: Icons.home_rounded, label: 'Home', onTabTapped: onTabTapped),
|
NavbarItem(
|
||||||
NavbarItem(currentIndex: currentIndex, index: 1, icon: Icons.gamepad_rounded, label: 'Games', onTabTapped: onTabTapped),
|
index: 0,
|
||||||
NavbarItem(currentIndex: currentIndex, index: 2, icon: Icons.group_rounded, label: 'Groups', onTabTapped: onTabTapped),
|
isSelected: currentIndex == 0,
|
||||||
NavbarItem(currentIndex: currentIndex, index: 3, icon: Icons.bar_chart_rounded, label: 'Stats', onTabTapped: onTabTapped),
|
icon: Icons.home_rounded,
|
||||||
|
label: 'Home',
|
||||||
|
onTabTapped: onTabTapped,
|
||||||
|
),
|
||||||
|
NavbarItem(
|
||||||
|
index: 1,
|
||||||
|
isSelected: currentIndex == 1,
|
||||||
|
icon: Icons.gamepad_rounded,
|
||||||
|
label: 'Games',
|
||||||
|
onTabTapped: onTabTapped,
|
||||||
|
flixcoo marked this conversation as resolved
Outdated
|
|||||||
|
),
|
||||||
|
NavbarItem(
|
||||||
|
index: 2,
|
||||||
|
gelbeinhalb marked this conversation as resolved
Outdated
flixcoo
commented
Chat GPT kommentare? Chat GPT kommentare?
|
|||||||
|
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,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class NavbarItem extends StatefulWidget {
|
class NavbarItem extends StatefulWidget {
|
||||||
|
|
||||||
final int currentIndex;
|
|
||||||
final int index;
|
final int index;
|
||||||
|
final bool isSelected;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String label;
|
final String label;
|
||||||
final Function(int) onTabTapped;
|
final Function(int) onTabTapped;
|
||||||
|
|
||||||
const NavbarItem(
|
const NavbarItem({
|
||||||
{super.key, required this.currentIndex, required this.index,
|
super.key,
|
||||||
required this.icon, required this.label, required this.onTabTapped
|
required this.index,
|
||||||
}
|
required this.isSelected,
|
||||||
);
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
required this.onTabTapped,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<NavbarItem> createState() => _NavbarItemState();
|
State<NavbarItem> createState() => _NavbarItemState();
|
||||||
@@ -21,9 +23,6 @@ class NavbarItem extends StatefulWidget {
|
|||||||
class _NavbarItemState extends State<NavbarItem> {
|
class _NavbarItemState extends State<NavbarItem> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
flixcoo marked this conversation as resolved
Outdated
flixcoo
commented
Ggf. andere möglichkeit finden für isSelected, übergeben als Parameter Ggf. andere möglichkeit finden für isSelected, übergeben als Parameter
gelbeinhalb
commented
ja überleg dir ma was ja überleg dir ma was
flixcoo
commented
Du könntest z.B. einen Parameter Du könntest z.B. einen Parameter `isSelected` übergeben der gesetzt wird wenn `currentIndex == 0 // 1, 2, 3`, also folgendermaßen:
```dart
NavbarItem(isSelected: currentIndex == 0, icon: Icons.home_rounded, label: 'Home', onTap: onTabTapped)
```
gelbeinhalb
commented
wäre das fine mit dir? wäre das fine mit dir?
```dart
NavbarItem(index: 1, isSelected: currentIndex == 1, icon: Icons.gamepad_rounded, label: 'Games', onTabTapped: onTabTapped )
```
|
|||||||
|
|
||||||
bool isSelected = widget.currentIndex == widget.index;
|
|
||||||
|
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => widget.onTabTapped(widget.index),
|
onTap: () => widget.onTabTapped(widget.index),
|
||||||
@@ -36,15 +35,17 @@ class _NavbarItemState extends State<NavbarItem> {
|
|||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
widget.icon,
|
widget.icon,
|
||||||
color: isSelected ? Colors.white : Colors.black,
|
color: widget.isSelected ? Colors.white : Colors.black,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
widget.label,
|
widget.label,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: isSelected ? Colors.white : Colors.black,
|
color: widget.isSelected ? Colors.white : Colors.black,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
fontWeight: widget.isSelected
|
||||||
|
? FontWeight.bold
|
||||||
|
: FontWeight.normal,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user
Ich würde das Widget entweder Auslagern (als
nav_item.dartimwidgetsOrdner) oder dasExpandedWidget direkt in die Row setzen (nicht so geil). Wenn du das Auslagerst sparst du dir ganz viel Code hier und übergibst die Parameter einfach direkt in das Widget.Ja stimmt.
Ich lager das dann aus.