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-28 11:27:45 -04:00
|
|
|
import 'package:google_fonts/google_fonts.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-03-02 13:59:50 -05:00
|
|
|
import 'notifications/notification_list.dart';
|
2026-03-02 19:41:01 -05:00
|
|
|
import 'utils/pref_utils.dart';
|
2026-02-11 14:07:27 -05:00
|
|
|
|
|
|
|
|
// Routes definitions
|
|
|
|
|
final GoRouter router = GoRouter(
|
2026-03-02 19:41:01 -05:00
|
|
|
// If there is no API base URL send the user to settings
|
2026-03-02 13:59:50 -05:00
|
|
|
initialLocation: '/notifications',
|
2026-02-11 14:07:27 -05:00
|
|
|
routes: [
|
|
|
|
|
ShellRoute(
|
|
|
|
|
builder: (context, state, child) {
|
|
|
|
|
return MainShell(child: child);
|
|
|
|
|
},
|
|
|
|
|
routes: [
|
|
|
|
|
GoRoute(
|
2026-03-02 13:59:50 -05:00
|
|
|
path: '/notifications',
|
|
|
|
|
name: 'notifications',
|
|
|
|
|
builder: (context, state) => NotificationList(),
|
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
|
|
|
),
|
|
|
|
|
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) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2026-05-28 11:27:45 -04:00
|
|
|
title: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
'OOTT',
|
|
|
|
|
style: GoogleFonts.barlowCondensed(
|
|
|
|
|
color: Theme.of(context).colorScheme.onPrimary,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 26,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-02-11 18:31:12 -05:00
|
|
|
backgroundColor: Theme.of(
|
|
|
|
|
context,
|
|
|
|
|
).colorScheme.surfaceContainerLowest,
|
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-02-11 14:07:27 -05:00
|
|
|
extended: constraints.maxWidth >= 600,
|
|
|
|
|
destinations: [
|
|
|
|
|
NavigationRailDestination(
|
|
|
|
|
icon: Icon(Icons.notifications_outlined),
|
|
|
|
|
selectedIcon: Icon(Icons.notifications),
|
2026-03-02 13:59:50 -05:00
|
|
|
label: Text('Notifications'),
|
2026-02-11 14:07:27 -05:00
|
|
|
),
|
|
|
|
|
NavigationRailDestination(
|
|
|
|
|
icon: Icon(Icons.devices_other_outlined),
|
|
|
|
|
selectedIcon: Icon(Icons.devices_other),
|
|
|
|
|
label: Text('Devices'),
|
|
|
|
|
),
|
|
|
|
|
NavigationRailDestination(
|
|
|
|
|
icon: Icon(Icons.settings_outlined),
|
|
|
|
|
selectedIcon: Icon(Icons.settings),
|
|
|
|
|
label: Text('Settings'),
|
|
|
|
|
),
|
|
|
|
|
NavigationRailDestination(
|
|
|
|
|
icon: Icon(Icons.info_outline),
|
|
|
|
|
selectedIcon: Icon(Icons.info),
|
|
|
|
|
label: Text('About'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
selectedIndex: _calculateSelectedIndex(context),
|
|
|
|
|
onDestinationSelected: (index) =>
|
|
|
|
|
_onDestinationSelected(index, context),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.all(20),
|
2026-02-11 18:31:12 -05:00
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2026-02-11 14:07:27 -05:00
|
|
|
child: child,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-03-02 13:59:50 -05:00
|
|
|
if (location.startsWith('/notifications')) return 0;
|
2026-02-11 14:07:27 -05:00
|
|
|
if (location.startsWith('/devices')) return 1;
|
|
|
|
|
if (location.startsWith('/settings')) return 2;
|
|
|
|
|
if (location.startsWith('/about')) return 3;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onDestinationSelected(int index, BuildContext context) {
|
|
|
|
|
switch (index) {
|
|
|
|
|
case 0:
|
2026-03-02 13:59:50 -05:00
|
|
|
context.go('/notifications');
|
2026-02-11 14:07:27 -05:00
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
context.go('/devices');
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
context.go('/settings');
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
context.go('/about');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|