60 lines
1.6 KiB
Dart
60 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:phone_login/auth/auth_state.dart';
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
int _selectedIndex = 0;
|
|
|
|
void _onItemTapped(int index) {
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
});
|
|
if (index == 1) {
|
|
context.go('/profile');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final authState = Provider.of<AuthState>(context);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Home')),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
if (authState.isLoggedIn)
|
|
const Text('Welcome back!')
|
|
else
|
|
const Text('Please log in.'),
|
|
const SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
authState.toggleLogin();
|
|
},
|
|
child: Text(authState.isLoggedIn ? 'Logout' : 'Login'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
items: const <BottomNavigationBarItem>[
|
|
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
|
|
],
|
|
currentIndex: _selectedIndex,
|
|
onTap: _onItemTapped,
|
|
),
|
|
);
|
|
}
|
|
}
|