Code Cleanup
This commit is contained in:
102
finlog_app/app/lib/core/app/router.dart
Normal file
102
finlog_app/app/lib/core/app/router.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:app/modules/app_shell.dart';
|
||||
import 'package:app/modules/budget/budget_view.dart';
|
||||
import 'package:app/modules/dashboard/dashboard_view.dart';
|
||||
import 'package:app/modules/login/pages/login_page.dart';
|
||||
import 'package:app/modules/settings/settings_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:animations/animations.dart';
|
||||
|
||||
enum AppRoute {
|
||||
login('/login'),
|
||||
home('/home'),
|
||||
inventory('/inventory'),
|
||||
inventoryAdd('/inventory/add'),
|
||||
budget('/budget'),
|
||||
expenses('/expenses'),
|
||||
reports('/reports'),
|
||||
settings('/settings');
|
||||
|
||||
const AppRoute(this.path);
|
||||
|
||||
final String path;
|
||||
}
|
||||
|
||||
class AnimatedPage<T> extends CustomTransitionPage<T> {
|
||||
AnimatedPage({
|
||||
required LocalKey super.key,
|
||||
required super.child,
|
||||
Duration duration = const Duration(milliseconds: 400),
|
||||
SharedAxisTransitionType transitionType =
|
||||
SharedAxisTransitionType.horizontal,
|
||||
}) : super(
|
||||
transitionDuration: duration,
|
||||
transitionsBuilder: (context, animation, secondary, child) {
|
||||
return SharedAxisTransition(
|
||||
animation: animation,
|
||||
secondaryAnimation: secondary,
|
||||
transitionType: transitionType,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
GoRoute _r(
|
||||
AppRoute route,
|
||||
Widget Function(BuildContext, GoRouterState) builder, {
|
||||
List<RouteBase> routes = const [],
|
||||
SharedAxisTransitionType transitionType = SharedAxisTransitionType.horizontal,
|
||||
}) {
|
||||
return GoRoute(
|
||||
path: route.path,
|
||||
name: route.name,
|
||||
pageBuilder: (context, state) => AnimatedPage<void>(
|
||||
key: state.pageKey,
|
||||
child: builder(context, state),
|
||||
transitionType: transitionType,
|
||||
),
|
||||
routes: routes,
|
||||
);
|
||||
}
|
||||
|
||||
GoRouter buildAppRouter(AppRoute initialRoute) {
|
||||
return GoRouter(
|
||||
initialLocation: initialRoute.path,
|
||||
routes: [
|
||||
// Login separat, ohne Shell
|
||||
_r(AppRoute.login, (ctx, st) => const LoginPage()),
|
||||
|
||||
// App-Inhalte innerhalb der Shell (AppBar + Drawer bleiben stehen)
|
||||
ShellRoute(
|
||||
builder: (context, state, child) => AppShell(child: child),
|
||||
routes: [
|
||||
_r(AppRoute.home, (ctx, st) => const DashboardView()),
|
||||
_r(AppRoute.budget, (ctx, st) => const BudgetView()),
|
||||
_r(AppRoute.settings, (ctx, st) => const SettingsView()),
|
||||
|
||||
// Stubs – aktualisiere hier, wenn deine Seiten fertig sind:
|
||||
_r(
|
||||
AppRoute.inventory,
|
||||
(ctx, st) => const Center(child: Text('Inventar')),
|
||||
routes: [
|
||||
_r(
|
||||
AppRoute.inventoryAdd,
|
||||
(ctx, st) => const Center(child: Text('Inventar: Hinzufügen')),
|
||||
),
|
||||
],
|
||||
),
|
||||
_r(
|
||||
AppRoute.expenses,
|
||||
(ctx, st) => const Center(child: Text('Ausgaben')),
|
||||
),
|
||||
_r(
|
||||
AppRoute.reports,
|
||||
(ctx, st) =>
|
||||
const Center(child: Text('Reports – Auswertungen & Diagramme')),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:app/core/app/router.dart';
|
||||
|
||||
class InitializeAppUseCase {
|
||||
Future<AppRoute> call() async {
|
||||
// Beispiel: ggf. weitere Init-Schritte
|
||||
// await _migrateIfNeeded(prefs);
|
||||
// await _warmupCaches();
|
||||
|
||||
// return auth.isLoggedIn ? AppRoute.home : AppRoute.login;
|
||||
return AppRoute.login;
|
||||
}
|
||||
}
|
||||
58
finlog_app/app/lib/core/app/theme.dart
Normal file
58
finlog_app/app/lib/core/app/theme.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttery/fluttery.dart';
|
||||
import 'package:fluttery/preferences.dart';
|
||||
|
||||
/// Controls the current theme of the application.
|
||||
/// Loads the theme from Preferences or falls back to system default.
|
||||
class ThemeController extends ChangeNotifier {
|
||||
final Preferences _prefs;
|
||||
|
||||
// vars
|
||||
ThemeMode _themeMode = ThemeMode.system;
|
||||
|
||||
/// Constructor
|
||||
ThemeController() : _prefs = App.service<Preferences>();
|
||||
|
||||
/// Loads theme from Preferences (or defaults to system).
|
||||
Future<void> init() async {
|
||||
final saved = await _prefs.getString('theme');
|
||||
if (saved == null) {
|
||||
_themeMode = ThemeMode.system;
|
||||
} else {
|
||||
_themeMode = _fromString(saved);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Sets theme and persists it in Preferences.
|
||||
Future<void> setTheme(ThemeMode mode) async {
|
||||
_themeMode = mode;
|
||||
notifyListeners();
|
||||
await _prefs.setString('theme', _toString(mode));
|
||||
}
|
||||
|
||||
ThemeMode _fromString(String value) {
|
||||
switch (value) {
|
||||
case 'light':
|
||||
return ThemeMode.light;
|
||||
case 'dark':
|
||||
return ThemeMode.dark;
|
||||
case 'system':
|
||||
default:
|
||||
return ThemeMode.system;
|
||||
}
|
||||
}
|
||||
|
||||
String _toString(ThemeMode mode) {
|
||||
switch (mode) {
|
||||
case ThemeMode.light:
|
||||
return 'light';
|
||||
case ThemeMode.dark:
|
||||
return 'dark';
|
||||
case ThemeMode.system:
|
||||
return 'system';
|
||||
}
|
||||
}
|
||||
|
||||
ThemeMode get themeMode => _themeMode;
|
||||
}
|
||||
Reference in New Issue
Block a user