first commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
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 'login_screen.dart';
|
||||
import 'camera_screen.dart';
|
||||
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
_HomeScreenState createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
int _selectedIndex = 1; // Default to Shooting Screen
|
||||
|
||||
static final List<Widget> _pages = <Widget>[
|
||||
BookScreen(),
|
||||
TargetScreen(),
|
||||
Placeholder(), // Placeholder for Scan - optional
|
||||
CalendarScreen(),
|
||||
SettingsScreen(),
|
||||
];
|
||||
|
||||
static final List<String> _pageTitles = [
|
||||
'Book',
|
||||
'Shooting',
|
||||
'Scan',
|
||||
'Calendar',
|
||||
'Settings'
|
||||
];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
if (index == 2) {
|
||||
_openCameraScan();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
//void _logout() {
|
||||
// Navigator.of(context).pushAndRemoveUntil(
|
||||
// MaterialPageRoute(builder: (context) => const LoginScreen()),
|
||||
// (Route<dynamic> route) => false,
|
||||
// );
|
||||
//}
|
||||
|
||||
// When opening the camera screen, ensure the shooting screen is always selected after returning
|
||||
void _openCameraScan() async {
|
||||
// Navigate to CameraScreen
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const CameraScreen()),
|
||||
);
|
||||
|
||||
// After returning, ensure that Shooting screen (index 1) is selected
|
||||
setState(() {
|
||||
_selectedIndex = 1;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
_pageTitles[_selectedIndex],
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
backgroundColor: Colors.grey[900],
|
||||
iconTheme: const IconThemeData(color: Colors.white),
|
||||
automaticallyImplyLeading: false,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout, color: Colors.red),
|
||||
onPressed: null, // disables the button
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _pages[_selectedIndex],
|
||||
bottomNavigationBar: BottomNavBar(
|
||||
selectedIndex: _selectedIndex,
|
||||
onItemTapped: _onItemTapped,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user