feat: Refactor HomeScreen for login-based UI and restore Firebase dependencies
Refactors the HomeScreen to dynamically display content based on the user's authentication status. - Migrated HomeScreen from StatefulWidget to StatelessWidget. - Introduced Consumer<AuthState> to listen for authentication changes. - Implemented placeholder _LoggedInView and _LoggedOutView widgets for conditional rendering. - Restored irebase_core and irebase_auth dependencies to pubspec.yaml and main.dart which were inadvertently removed by dart_fix. - Removed outdated state management for bottom navigation bar. - Addressed dart fix warnings and ensured code formatting.
This commit is contained in:
@@ -1,59 +1,39 @@
|
||||
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 {
|
||||
class HomeScreen extends StatelessWidget {
|
||||
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();
|
||||
body: Consumer<AuthState>(
|
||||
builder: (context, authState, child) {
|
||||
return authState.isLoggedIn
|
||||
? const _LoggedInView()
|
||||
: const _LoggedOutView();
|
||||
},
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LoggedInView extends StatelessWidget {
|
||||
const _LoggedInView();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(child: Text('Logged In'));
|
||||
}
|
||||
}
|
||||
|
||||
class _LoggedOutView extends StatelessWidget {
|
||||
const _LoggedOutView();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(child: Text('Logged Out'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
firebase_core: ^4.3.0
|
||||
firebase_auth: ^6.1.3
|
||||
go_router: ^17.0.1
|
||||
provider: ^6.1.5+1
|
||||
intl_phone_field: ^3.2.0
|
||||
pinput: ^6.0.1
|
||||
firebase_core: 4.3.0
|
||||
firebase_auth: 6.1.3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user