2026-02-11 14:07:27 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2026-05-28 17:29:55 -04:00
|
|
|
import 'package:frontend/about/about.dart';
|
2026-03-02 19:41:01 -05:00
|
|
|
import 'package:frontend/settings/settings.dart';
|
2026-02-11 14:07:27 -05:00
|
|
|
import 'package:go_router/go_router.dart';
|
2026-05-27 18:24:35 -04:00
|
|
|
import 'devices/device_detail.dart';
|
2026-05-27 14:58:11 -04:00
|
|
|
import 'devices/device_list.dart';
|
2026-05-28 19:10:08 -04:00
|
|
|
import 'home/home_screen.dart';
|
2026-05-28 18:16:04 -04:00
|
|
|
import 'status/status_screen.dart';
|
2026-06-04 08:39:37 -04:00
|
|
|
import 'theme/dimens.dart';
|
2026-03-02 19:41:01 -05:00
|
|
|
import 'utils/pref_utils.dart';
|
2026-05-31 18:21:55 -04:00
|
|
|
import 'widgets/offline_banner.dart';
|
2026-02-11 14:07:27 -05:00
|
|
|
|
2026-05-28 19:51:31 -04:00
|
|
|
typedef _NavDest = ({IconData icon, IconData activeIcon, String label});
|
|
|
|
|
|
|
|
|
|
const List<_NavDest> _destinations = [
|
|
|
|
|
(icon: Icons.home_outlined, activeIcon: Icons.home, label: 'Home'),
|
|
|
|
|
(
|
|
|
|
|
icon: Icons.devices_other_outlined,
|
|
|
|
|
activeIcon: Icons.devices_other,
|
|
|
|
|
label: 'Devices',
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
icon: Icons.monitor_heart_outlined,
|
|
|
|
|
activeIcon: Icons.monitor_heart,
|
|
|
|
|
label: 'Status',
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
icon: Icons.settings_outlined,
|
|
|
|
|
activeIcon: Icons.settings,
|
|
|
|
|
label: 'Settings',
|
|
|
|
|
),
|
|
|
|
|
(icon: Icons.info_outline, activeIcon: Icons.info, label: 'About'),
|
|
|
|
|
];
|
|
|
|
|
|
2026-05-29 15:13:00 -04:00
|
|
|
// Observer used to notify subscribed routes when another route is pushed
|
|
|
|
|
// on top of or popped from them, so they can refresh stale data.
|
|
|
|
|
final RouteObserver<ModalRoute<void>> routeObserver =
|
|
|
|
|
RouteObserver<ModalRoute<void>>();
|
|
|
|
|
|
2026-02-11 14:07:27 -05:00
|
|
|
// Routes definitions
|
|
|
|
|
final GoRouter router = GoRouter(
|
2026-06-01 07:17:41 -04:00
|
|
|
initialLocation: '/',
|
2026-02-11 14:07:27 -05:00
|
|
|
routes: [
|
|
|
|
|
ShellRoute(
|
2026-05-29 15:13:00 -04:00
|
|
|
observers: [routeObserver],
|
2026-02-11 14:07:27 -05:00
|
|
|
builder: (context, state, child) {
|
|
|
|
|
return MainShell(child: child);
|
|
|
|
|
},
|
|
|
|
|
routes: [
|
|
|
|
|
GoRoute(
|
2026-06-01 07:17:41 -04:00
|
|
|
path: '/',
|
|
|
|
|
name: 'home',
|
2026-05-28 19:10:08 -04:00
|
|
|
builder: (context, state) => const HomeScreen(),
|
2026-03-02 19:41:01 -05:00
|
|
|
redirect: (context, state) => _redirectToSettings(),
|
2026-02-11 14:07:27 -05:00
|
|
|
),
|
|
|
|
|
GoRoute(
|
|
|
|
|
path: '/devices',
|
|
|
|
|
name: 'devices',
|
2026-05-27 14:58:11 -04:00
|
|
|
builder: (context, state) => const DeviceList(),
|
2026-03-02 19:41:01 -05:00
|
|
|
redirect: (context, state) => _redirectToSettings(),
|
2026-05-27 18:24:35 -04:00
|
|
|
routes: [
|
|
|
|
|
GoRoute(
|
|
|
|
|
path: ':macAddress',
|
|
|
|
|
name: 'deviceDetail',
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
final mac = state.pathParameters['macAddress']!;
|
|
|
|
|
return DeviceDetail(macAddress: mac);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-02-11 14:07:27 -05:00
|
|
|
),
|
2026-05-28 18:16:04 -04:00
|
|
|
GoRoute(
|
|
|
|
|
path: '/status',
|
|
|
|
|
name: 'status',
|
|
|
|
|
builder: (context, state) => const StatusScreen(),
|
|
|
|
|
redirect: (context, state) => _redirectToSettings(),
|
|
|
|
|
),
|
2026-02-11 14:07:27 -05:00
|
|
|
GoRoute(
|
|
|
|
|
path: '/settings',
|
|
|
|
|
name: 'settings',
|
2026-03-02 19:41:01 -05:00
|
|
|
builder: (context, state) => Settings(),
|
2026-02-11 14:07:27 -05:00
|
|
|
),
|
|
|
|
|
GoRoute(
|
|
|
|
|
path: '/about',
|
|
|
|
|
name: 'about',
|
2026-05-28 17:29:55 -04:00
|
|
|
builder: (context, state) => const About(),
|
2026-02-11 14:07:27 -05:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Application shell and navigation
|
|
|
|
|
class MainShell extends StatelessWidget {
|
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
|
|
const MainShell({super.key, required this.child});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return LayoutBuilder(
|
|
|
|
|
builder: (context, constraints) {
|
2026-05-28 19:51:31 -04:00
|
|
|
final selectedIndex = _calculateSelectedIndex(context);
|
|
|
|
|
final width = constraints.maxWidth;
|
|
|
|
|
|
2026-06-04 08:39:37 -04:00
|
|
|
if (width < Breakpoints.medium) {
|
2026-05-28 19:51:31 -04:00
|
|
|
return Scaffold(
|
2026-06-04 08:39:37 -04:00
|
|
|
appBar: _buildAppBar(context, selectedIndex),
|
2026-05-31 18:21:55 -04:00
|
|
|
body: Column(
|
|
|
|
|
children: [
|
|
|
|
|
const OfflineBanner(),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
2026-06-04 08:39:37 -04:00
|
|
|
padding: const EdgeInsets.all(Insets.lg),
|
2026-05-31 18:21:55 -04:00
|
|
|
child: child,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-05-28 11:27:45 -04:00
|
|
|
),
|
2026-05-28 19:51:31 -04:00
|
|
|
bottomNavigationBar: NavigationBar(
|
|
|
|
|
selectedIndex: selectedIndex,
|
|
|
|
|
onDestinationSelected: (index) =>
|
|
|
|
|
_onDestinationSelected(index, context),
|
|
|
|
|
destinations: _destinations
|
|
|
|
|
.map(
|
|
|
|
|
(d) => NavigationDestination(
|
|
|
|
|
icon: Icon(d.icon),
|
|
|
|
|
selectedIcon: Icon(d.activeIcon),
|
|
|
|
|
label: d.label,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
2026-06-04 08:39:37 -04:00
|
|
|
appBar: _buildAppBar(context, selectedIndex),
|
2026-02-11 14:07:27 -05:00
|
|
|
body: Row(
|
|
|
|
|
children: [
|
|
|
|
|
SafeArea(
|
|
|
|
|
child: NavigationRail(
|
|
|
|
|
backgroundColor: Theme.of(
|
|
|
|
|
context,
|
2026-02-11 18:31:12 -05:00
|
|
|
).colorScheme.surfaceContainerLow,
|
2026-06-04 08:39:37 -04:00
|
|
|
extended: width >= Breakpoints.expanded,
|
2026-05-28 19:51:31 -04:00
|
|
|
destinations: _destinations
|
|
|
|
|
.map(
|
|
|
|
|
(d) => NavigationRailDestination(
|
|
|
|
|
icon: Icon(d.icon),
|
|
|
|
|
selectedIcon: Icon(d.activeIcon),
|
|
|
|
|
label: Text(d.label),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
|
|
|
|
selectedIndex: selectedIndex,
|
2026-02-11 14:07:27 -05:00
|
|
|
onDestinationSelected: (index) =>
|
|
|
|
|
_onDestinationSelected(index, context),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Container(
|
2026-02-11 18:31:12 -05:00
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2026-05-31 18:21:55 -04:00
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
const OfflineBanner(),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
2026-06-04 08:39:37 -04:00
|
|
|
padding: const EdgeInsets.all(Insets.lg),
|
2026-05-31 18:21:55 -04:00
|
|
|
child: child,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-02-11 14:07:27 -05:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-05-28 19:51:31 -04:00
|
|
|
|
2026-06-04 08:39:37 -04:00
|
|
|
AppBar _buildAppBar(BuildContext context, int selectedIndex) {
|
|
|
|
|
final theme = Theme.of(context);
|
2026-05-28 19:51:31 -04:00
|
|
|
return AppBar(
|
2026-06-04 08:39:37 -04:00
|
|
|
titleSpacing: Insets.lg,
|
|
|
|
|
title: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: theme.colorScheme.primary,
|
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
'OOTT',
|
|
|
|
|
style: theme.textTheme.headlineSmall?.copyWith(
|
|
|
|
|
color: theme.colorScheme.onPrimary,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-05-28 19:51:31 -04:00
|
|
|
),
|
2026-06-04 08:39:37 -04:00
|
|
|
const SizedBox(width: Insets.md),
|
|
|
|
|
Flexible(
|
|
|
|
|
child: Text(
|
|
|
|
|
_destinations[selectedIndex].label,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
style: theme.textTheme.titleLarge,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-05-28 19:51:31 -04:00
|
|
|
),
|
2026-06-04 08:39:37 -04:00
|
|
|
backgroundColor: theme.colorScheme.surfaceContainerLowest,
|
2026-05-28 19:51:31 -04:00
|
|
|
);
|
|
|
|
|
}
|
2026-02-11 14:07:27 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-02 19:41:01 -05:00
|
|
|
String? _redirectToSettings() {
|
|
|
|
|
return (PrefUtil.getValue("base_url", "") as String == "")
|
|
|
|
|
? '/settings'
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 14:07:27 -05:00
|
|
|
int _calculateSelectedIndex(BuildContext context) {
|
|
|
|
|
final location = GoRouterState.of(context).uri.path;
|
2026-06-01 07:17:41 -04:00
|
|
|
if (location == '/') return 0;
|
2026-02-11 14:07:27 -05:00
|
|
|
if (location.startsWith('/devices')) return 1;
|
2026-05-28 18:16:04 -04:00
|
|
|
if (location.startsWith('/status')) return 2;
|
|
|
|
|
if (location.startsWith('/settings')) return 3;
|
|
|
|
|
if (location.startsWith('/about')) return 4;
|
2026-02-11 14:07:27 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onDestinationSelected(int index, BuildContext context) {
|
|
|
|
|
switch (index) {
|
|
|
|
|
case 0:
|
2026-06-01 07:17:41 -04:00
|
|
|
context.go('/');
|
2026-02-11 14:07:27 -05:00
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
context.go('/devices');
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2026-05-28 18:16:04 -04:00
|
|
|
context.go('/status');
|
2026-02-11 14:07:27 -05:00
|
|
|
break;
|
|
|
|
|
case 3:
|
2026-05-28 18:16:04 -04:00
|
|
|
context.go('/settings');
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2026-02-11 14:07:27 -05:00
|
|
|
context.go('/about');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|