Navbar Anpassen #9
@@ -5,6 +5,7 @@ import 'package:game_tracker/presentation/views/main_menu/groups_view.dart';
|
|||||||
import 'package:game_tracker/presentation/views/main_menu/home_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/home_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/settings_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/settings_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/statistics_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/statistics_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/navbar_item.dart';
|
||||||
|
|
||||||
class CustomNavigationBar extends StatefulWidget {
|
class CustomNavigationBar extends StatefulWidget {
|
||||||
const CustomNavigationBar({super.key});
|
const CustomNavigationBar({super.key});
|
||||||
@@ -66,10 +67,10 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
_buildNavItem(Icons.home, 'Home', 0),
|
NavbarItem(currentIndex: currentIndex, index: 0, icon: Icons.home_rounded, label: 'Home', onTabTapped: onTabTapped),
|
||||||
_buildNavItem(Icons.history, 'Games', 1),
|
NavbarItem(currentIndex: currentIndex, index: 1, icon: Icons.gamepad_rounded, label: 'Games', onTabTapped: onTabTapped),
|
||||||
_buildNavItem(Icons.groups, 'Groups', 2),
|
NavbarItem(currentIndex: currentIndex, index: 2, icon: Icons.group_rounded, label: 'Groups', onTabTapped: onTabTapped),
|
||||||
_buildNavItem(Icons.bar_chart, 'Stats', 3),
|
NavbarItem(currentIndex: currentIndex, index: 3, icon: Icons.bar_chart_rounded, label: 'Stats', onTabTapped: onTabTapped),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -79,39 +80,6 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flixcoo marked this conversation as resolved
Outdated
|
|||||||
Widget _buildNavItem(IconData icon, String label, int index) {
|
|
||||||
final isSelected = currentIndex == index;
|
|
||||||
|
|
||||||
return Expanded(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => onTabTapped(index),
|
|
||||||
behavior: HitTestBehavior.opaque,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
color: isSelected ? Colors.white : Colors.black,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: TextStyle(
|
|
||||||
color: isSelected ? Colors.white : Colors.black,
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onTabTapped(int index) {
|
void onTabTapped(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
currentIndex = index;
|
currentIndex = index;
|
||||||
|
gelbeinhalb marked this conversation as resolved
Outdated
flixcoo
commented
Chat GPT kommentare? Chat GPT kommentare?
|
|||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class NavbarItem extends StatefulWidget {
|
class NavbarItem extends StatefulWidget {
|
||||||
const NavbarItem({super.key});
|
|
||||||
|
final int currentIndex;
|
||||||
|
final int index;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<NavbarItem> createState() => _NavbarItemState();
|
State<NavbarItem> createState() => _NavbarItemState();
|
||||||
@@ -10,6 +21,36 @@ class NavbarItem extends StatefulWidget {
|
|||||||
class _NavbarItemState extends State<NavbarItem> {
|
class _NavbarItemState extends State<NavbarItem> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Placeholder();
|
|
||||||
|
bool isSelected = widget.currentIndex == widget.index;
|
||||||
|
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 )
```
|
|||||||
|
|
||||||
|
return Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () => widget.onTabTapped(widget.index),
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 5.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
widget.icon,
|
||||||
|
color: isSelected ? Colors.white : Colors.black,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
widget.label,
|
||||||
|
style: TextStyle(
|
||||||
|
color: isSelected ? Colors.white : Colors.black,
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: 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.