102 lines
3.2 KiB
Dart
102 lines
3.2 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 '../services/app_settings.dart';
|
|
|
|
enum AppTab { book, shooting, camera, calendar, settings }
|
|
|
|
/// The five tabs. Every page draws its own large title (see PageHeader);
|
|
/// the camera opens as its own screen.
|
|
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, IconData)> _icons = {
|
|
AppTab.book: (Icons.menu_book_outlined, Icons.menu_book_rounded),
|
|
AppTab.shooting: (Icons.gps_fixed_rounded, Icons.gps_fixed_rounded),
|
|
AppTab.camera: (Icons.photo_camera_outlined, Icons.photo_camera_rounded),
|
|
AppTab.calendar: (Icons.calendar_today_outlined, Icons.calendar_today_rounded),
|
|
AppTab.settings: (Icons.tune_rounded, Icons.tune_rounded),
|
|
};
|
|
|
|
// 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 {
|
|
// The photo camera is dark in both themes
|
|
AppSettings.instance.holdDark();
|
|
await Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (context) => const CameraScreen()),
|
|
);
|
|
AppSettings.instance.releaseDark();
|
|
if (mounted) 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(
|
|
body: KeyedSubtree(key: ValueKey(_selected), child: _page(_selected)),
|
|
bottomNavigationBar: BottomNavBar(
|
|
selectedIndex: tabs.indexOf(_selected),
|
|
onItemTapped: (i) => _onTabTapped(tabs[i]),
|
|
items: [
|
|
for (final tab in tabs) NavItem(_icons[tab]!.$1, _icons[tab]!.$2, settings.t(_titles[tab]!)),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|