130 lines
3.9 KiB
Dart
130 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'book_screen.dart';
|
|
import 'calendar_screen.dart';
|
|
import 'settings_screen.dart';
|
|
import 'target_screen.dart';
|
|
import '../widgets/bottom_nav.dart';
|
|
import 'camera_screen.dart';
|
|
import 'spectator_screen.dart';
|
|
import '../services/app_settings.dart';
|
|
import '../theme/app_theme.dart';
|
|
|
|
enum AppTab { book, shooting, camera, calendar, settings }
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
AppTab _selected = AppTab.shooting;
|
|
|
|
static const Map<AppTab, String> _titles = {
|
|
AppTab.book: 'Book',
|
|
AppTab.shooting: 'Shooting',
|
|
AppTab.camera: 'Camera',
|
|
AppTab.calendar: 'Calendar',
|
|
AppTab.settings: 'Settings',
|
|
};
|
|
|
|
static const Map<AppTab, IconData> _icons = {
|
|
AppTab.book: Icons.book,
|
|
AppTab.shooting: Icons.my_location,
|
|
AppTab.camera: Icons.camera_alt,
|
|
AppTab.calendar: Icons.calendar_today,
|
|
AppTab.settings: Icons.settings,
|
|
};
|
|
|
|
// Calendar is only shown to club members (see Settings > Club code)
|
|
List<AppTab> get _visibleTabs => [
|
|
for (final tab in AppTab.values)
|
|
if (tab != AppTab.calendar || AppSettings.instance.clubUnlocked) tab,
|
|
];
|
|
|
|
Widget _page(AppTab tab) {
|
|
switch (tab) {
|
|
case AppTab.book:
|
|
return const BookScreen();
|
|
case AppTab.shooting:
|
|
case AppTab.camera: // camera opens as its own route, never shown here
|
|
return const TargetScreen();
|
|
case AppTab.calendar:
|
|
return const CalendarScreen();
|
|
case AppTab.settings:
|
|
return const SettingsScreen();
|
|
}
|
|
}
|
|
|
|
void _onTabTapped(AppTab tab) {
|
|
if (tab == AppTab.camera) {
|
|
_openCameraScan();
|
|
return;
|
|
}
|
|
setState(() => _selected = tab);
|
|
}
|
|
|
|
// When returning from the camera screen, always land on the Shooting tab
|
|
void _openCameraScan() async {
|
|
await Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (context) => const CameraScreen()),
|
|
);
|
|
setState(() => _selected = AppTab.shooting);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: AppSettings.instance,
|
|
builder: (context, _) {
|
|
final settings = AppSettings.instance;
|
|
final tabs = _visibleTabs;
|
|
if (!tabs.contains(_selected)) _selected = AppTab.settings; // calendar was just locked
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(
|
|
settings.t(_titles[_selected]!),
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
backgroundColor: AppTheme.bar,
|
|
iconTheme: const IconThemeData(color: Colors.white),
|
|
automaticallyImplyLeading: false,
|
|
scrolledUnderElevation: 0, // For Material 3 (Flutter 3.7+)
|
|
actions: [
|
|
if (_selected == AppTab.shooting)
|
|
IconButton(
|
|
icon: const Icon(Icons.visibility_rounded, color: Colors.white),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => SpectatorScreen(
|
|
selectedLanguage: settings.language,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
backgroundColor: settings.backgroundColor,
|
|
body: _page(_selected),
|
|
bottomNavigationBar: BottomNavBar(
|
|
selectedIndex: tabs.indexOf(_selected),
|
|
onItemTapped: (i) => _onTabTapped(tabs[i]),
|
|
items: [
|
|
for (final tab in tabs)
|
|
BottomNavigationBarItem(
|
|
icon: Icon(_icons[tab]),
|
|
label: settings.t(_titles[tab]!),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|