Cleanup
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import 'package:app/core/app/router.dart';
|
||||
import 'package:app/core/features/feature_controller.dart';
|
||||
import 'package:app/core/i18n/translations.g.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class AppShell extends StatefulWidget {
|
||||
final Widget child;
|
||||
@@ -12,7 +15,7 @@ class AppShell extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AppShellState extends State<AppShell> {
|
||||
static const double _breakpoint = 800; // Tablet/Desktop threshold
|
||||
static const double _breakpoint = 800;
|
||||
final FocusNode _contentFocus = FocusNode(debugLabel: 'contentFocus');
|
||||
|
||||
@override
|
||||
@@ -23,7 +26,7 @@ class _AppShellState extends State<AppShell> {
|
||||
|
||||
// --- NAV ITEMS -------------------------------------------------------------
|
||||
|
||||
// Desktop/Tablet drawer items (you can keep them rich/longer here)
|
||||
// Desktop/Tablet drawer items
|
||||
List<({IconData icon, IconData? selectedIcon, String label, String route})>
|
||||
_getDesktopItems(BuildContext context) {
|
||||
final t = Translations.of(context);
|
||||
@@ -32,46 +35,61 @@ class _AppShellState extends State<AppShell> {
|
||||
icon: Icons.dashboard_outlined,
|
||||
selectedIcon: Icons.dashboard,
|
||||
label: t.app.navigationDashboard,
|
||||
route: '/',
|
||||
route: AppRoute.home.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.account_balance_wallet_outlined,
|
||||
selectedIcon: Icons.account_balance_wallet,
|
||||
label: t.app.navigationBudgets,
|
||||
route: '/budget',
|
||||
label: t.app.navigationBudgets, // Haushaltsbereich inkl. Budget
|
||||
route: AppRoute.budget.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.inventory_2_outlined,
|
||||
selectedIcon: Icons.inventory_2,
|
||||
label: t.app.navigationInventory,
|
||||
route: '/inventory',
|
||||
route: AppRoute.inventory.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.bar_chart_outlined,
|
||||
selectedIcon: Icons.bar_chart,
|
||||
label: t.app.navigationReports,
|
||||
route: '/reports',
|
||||
route: AppRoute.reports.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.settings_outlined,
|
||||
selectedIcon: Icons.settings,
|
||||
label: t.app.navigationSettings,
|
||||
route: '/settings',
|
||||
route: AppRoute.settings.path,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
// Mobile bottom bar items (exactly the four you asked for)
|
||||
// Mobile bottom bar items (4 Tabs)
|
||||
List<({IconData icon, String label, String route})> _getMobileTabs(
|
||||
BuildContext context,
|
||||
) {
|
||||
final t = Translations.of(context);
|
||||
return [
|
||||
(icon: Icons.dashboard, label: t.app.navigationDashboard, route: '/home'),
|
||||
// “Haushalt (inkl. Budget)” → map to /budget for now
|
||||
(icon: Icons.home, label: 'Haushalt', route: '/budget'),
|
||||
(icon: Icons.inventory_2, label: 'Inventar', route: '/inventory'),
|
||||
(icon: Icons.directions_car, label: 'Auto', route: '/car'),
|
||||
(
|
||||
icon: Icons.dashboard,
|
||||
label: t.app.navigationDashboard,
|
||||
route: AppRoute.home.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.home,
|
||||
label: (t.app.navigationHousehold),
|
||||
route: AppRoute.budget.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.inventory_2,
|
||||
label: t.app.navigationInventory,
|
||||
route: AppRoute.inventory.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.directions_car,
|
||||
label: (t.app.navigationCar),
|
||||
route: AppRoute.car.path,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -82,13 +100,18 @@ class _AppShellState extends State<AppShell> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _goForIndex<T>(
|
||||
BuildContext ctx,
|
||||
int i,
|
||||
List<T> items,
|
||||
String Function(T) routeOf,
|
||||
) {
|
||||
ctx.go(routeOf(items[i]));
|
||||
// Route→Feature-Guard
|
||||
bool _routeEnabled(String route, FeatureController fc) {
|
||||
if (route.startsWith(AppRoute.home.path)) return true;
|
||||
if (route.startsWith(AppRoute.settings.path)) return true;
|
||||
|
||||
if (route.startsWith(AppRoute.budget.path)) return fc.hasHousehold;
|
||||
if (route.startsWith(AppRoute.inventory.path)) return fc.hasInventory;
|
||||
if (route.startsWith(AppRoute.car.path)) return fc.hasCar;
|
||||
if (route.startsWith(AppRoute.reports.path)) return fc.hasReports;
|
||||
|
||||
// Default: sichtbar
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -107,16 +130,8 @@ class _AppShellState extends State<AppShell> {
|
||||
|
||||
final appBar = AppBar(
|
||||
title: const _LogoHeader(),
|
||||
// On desktop we use a persistent drawer, so no burger button.
|
||||
leading: isDesktop
|
||||
? null
|
||||
: Builder(
|
||||
builder: (ctx) => IconButton(
|
||||
icon: const Icon(Icons.menu),
|
||||
onPressed: () => Scaffold.of(ctx).openDrawer(),
|
||||
tooltip: t.app.tooltipMenu,
|
||||
),
|
||||
),
|
||||
// Kein Burger-Button, da mobil ohne Drawer (BottomNav) und Desktop mit persistentem Drawer
|
||||
leading: null,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: t.app.tooltipNotifications,
|
||||
@@ -125,7 +140,7 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
IconButton(
|
||||
tooltip: t.app.tooltipUserSettings,
|
||||
onPressed: () => context.push('/settings'),
|
||||
onPressed: () => context.push(AppRoute.settings.path),
|
||||
icon: const Icon(Icons.account_circle_outlined),
|
||||
),
|
||||
],
|
||||
@@ -133,21 +148,67 @@ class _AppShellState extends State<AppShell> {
|
||||
|
||||
if (!isDesktop) {
|
||||
// ------------------- MOBILE: Bottom Navigation -------------------
|
||||
final tabs = _getMobileTabs(context);
|
||||
final selected = _indexForPath(currentPath, tabs, (it) => it.route);
|
||||
final fc = context.read<FeatureController>();
|
||||
|
||||
// Wenn aktuelle Route deaktiviert ist, sanft nach Home umleiten
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final p = GoRouterState.of(context).matchedLocation;
|
||||
if (!_routeEnabled(p, fc)) {
|
||||
if (mounted) context.go(AppRoute.home.path);
|
||||
}
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
appBar: appBar,
|
||||
// Keep drawer for mobile? You asked for bottom bar instead — remove drawer.
|
||||
body: SafeArea(child: widget.child),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: selected,
|
||||
onDestinationSelected: (i) =>
|
||||
_goForIndex(context, i, tabs, (it) => it.route),
|
||||
destinations: [
|
||||
for (final it in tabs)
|
||||
NavigationDestination(icon: Icon(it.icon), label: it.label),
|
||||
],
|
||||
bottomNavigationBar: AnimatedBuilder(
|
||||
animation: fc,
|
||||
builder: (context, _) {
|
||||
final baseTabs = _getMobileTabs(context);
|
||||
|
||||
// Erlaubte Tabs filtern
|
||||
var tabs = <({IconData icon, String label, String route})>[
|
||||
for (final it in baseTabs)
|
||||
if (_routeEnabled(it.route, fc)) it,
|
||||
];
|
||||
|
||||
// Fallback: min. 2 Ziele sicherstellen
|
||||
if (tabs.length < 2) {
|
||||
// Home ist immer erlaubt; „Einstellungen“ als zweites Ziel ergänzen
|
||||
tabs = [
|
||||
// Stelle sicher, dass Home als erstes drin ist
|
||||
(
|
||||
icon: Icons.dashboard,
|
||||
label: Translations.of(context).app.navigationDashboard,
|
||||
route: AppRoute.home.path,
|
||||
),
|
||||
(
|
||||
icon: Icons.settings,
|
||||
label: Translations.of(context).app.navigationSettings,
|
||||
route: AppRoute.settings.path,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
// aktuellen Index robust bestimmen
|
||||
final currentPath = GoRouterState.of(context).matchedLocation;
|
||||
int selected = 0;
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
if (currentPath.startsWith(tabs[i].route)) {
|
||||
selected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NavigationBar(
|
||||
selectedIndex: selected,
|
||||
onDestinationSelected: (i) => context.go(tabs[i].route),
|
||||
destinations: [
|
||||
for (final it in tabs)
|
||||
NavigationDestination(icon: Icon(it.icon), label: it.label),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -194,87 +255,74 @@ class _DesktopDrawer extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final fc = context.read<FeatureController>();
|
||||
|
||||
return Material(
|
||||
elevation: 0,
|
||||
child: SafeArea(
|
||||
child: ListTileTheme(
|
||||
selectedColor: scheme.onSecondaryContainer,
|
||||
selectedTileColor: scheme.secondaryContainer,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
children: [
|
||||
const _LogoHeader(),
|
||||
const Divider(),
|
||||
for (var i = 0; i < items.length; i++)
|
||||
ListTile(
|
||||
selected: i == selectedIndex,
|
||||
leading: Icon(
|
||||
i == selectedIndex
|
||||
? (items[i].selectedIcon ?? items[i].icon)
|
||||
: items[i].icon,
|
||||
),
|
||||
title: Text(items[i].label),
|
||||
onTap: () => context.go(items[i].route),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
bool routeEnabled(String route) {
|
||||
if (route.startsWith(AppRoute.home.path)) return true;
|
||||
if (route.startsWith(AppRoute.settings.path)) return true;
|
||||
|
||||
class _AppDrawer extends StatelessWidget {
|
||||
final List<
|
||||
({IconData icon, IconData? selectedIcon, String label, String route})
|
||||
>
|
||||
items;
|
||||
final int selectedIndex;
|
||||
if (route.startsWith(AppRoute.budget.path)) return fc.hasHousehold;
|
||||
if (route.startsWith(AppRoute.inventory.path)) return fc.hasInventory;
|
||||
if (route.startsWith(AppRoute.car.path)) return fc.hasCar;
|
||||
if (route.startsWith(AppRoute.reports.path)) return fc.hasReports;
|
||||
|
||||
const _AppDrawer({required this.items, required this.selectedIndex});
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return AnimatedBuilder(
|
||||
animation: fc,
|
||||
builder: (context, _) {
|
||||
final visibleItems = [
|
||||
for (final it in items)
|
||||
if (routeEnabled(it.route)) it,
|
||||
];
|
||||
|
||||
return Drawer(
|
||||
child: SafeArea(
|
||||
child: ListTileTheme(
|
||||
selectedColor: scheme.onSecondaryContainer,
|
||||
selectedTileColor: scheme.secondaryContainer,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
children: [
|
||||
const _LogoHeader(),
|
||||
const Divider(),
|
||||
for (var i = 0; i < items.length; i++)
|
||||
ListTile(
|
||||
selected: i == selectedIndex,
|
||||
leading: Icon(
|
||||
i == selectedIndex
|
||||
? (items[i].selectedIcon ?? items[i].icon)
|
||||
: items[i].icon,
|
||||
),
|
||||
title: Text(items[i].label),
|
||||
onTap: () {
|
||||
Navigator.of(context).maybePop();
|
||||
context.go(items[i].route);
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.settings_outlined),
|
||||
title: Text(Translations.of(context).app.drawerSettings),
|
||||
onTap: () {
|
||||
Navigator.of(context).maybePop();
|
||||
context.go('/settings');
|
||||
},
|
||||
final currentPath = GoRouterState.of(context).matchedLocation;
|
||||
int safeSelected = 0;
|
||||
for (var i = 0; i < visibleItems.length; i++) {
|
||||
if (currentPath.startsWith(visibleItems[i].route)) {
|
||||
safeSelected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Material(
|
||||
elevation: 0,
|
||||
child: SafeArea(
|
||||
child: ListTileTheme(
|
||||
selectedColor: scheme.onSecondaryContainer,
|
||||
selectedTileColor: scheme.secondaryContainer,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
children: [
|
||||
const _LogoHeader(),
|
||||
const Divider(),
|
||||
for (var i = 0; i < visibleItems.length; i++)
|
||||
ListTile(
|
||||
selected: i == safeSelected,
|
||||
leading: Icon(
|
||||
i == safeSelected
|
||||
? (visibleItems[i].selectedIcon ??
|
||||
visibleItems[i].icon)
|
||||
: visibleItems[i].icon,
|
||||
),
|
||||
title: Text(visibleItems[i].label),
|
||||
onTap: () => context.go(visibleItems[i].route),
|
||||
),
|
||||
// Optional: Settings als fixer Eintrag,
|
||||
// falls du ihn unabhängig von items immer unten haben willst:
|
||||
// const Divider(),
|
||||
// ListTile(
|
||||
// leading: const Icon(Icons.settings_outlined),
|
||||
// title: Text(t.app.navigationSettings),
|
||||
// onTap: () => context.go(AppRoute.settings.path),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user