feat: Implement _LoggedInView UI and AuthState improvements
Implements the UI for the _LoggedInView in home_screen.dart, including: - An AppBar with a Profile icon that navigates to the profile screen. - A ListView.builder displaying example items. - A FloatingActionButton.extended for Logout that calls the `authState.logout()` method. - Adds a `logout()` method to `AuthState` to clear the login state. - Modifies the `toggleLogin()` method in `AuthState` to accept an optional boolean value for explicit state control. - Ensured code formatting and resolved any linting issues.
This commit is contained in:
@@ -4,8 +4,13 @@ class AuthState extends ChangeNotifier {
|
||||
bool _isLoggedIn = false;
|
||||
bool get isLoggedIn => _isLoggedIn;
|
||||
|
||||
void toggleLogin() {
|
||||
_isLoggedIn = !_isLoggedIn;
|
||||
void toggleLogin({bool? value}) {
|
||||
_isLoggedIn = value ?? !_isLoggedIn;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void logout() {
|
||||
_isLoggedIn = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,42 @@ class _LoggedInView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(child: Text('Logged In'));
|
||||
final authState = Provider.of<AuthState>(context, listen: false);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Welcome Back!'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.person),
|
||||
onPressed: () {
|
||||
context.go('/profile'); // Navigate to profile screen
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: 20, // Example items
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.all(8.0),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.star),
|
||||
title: Text('Item ${index + 1}'),
|
||||
subtitle: const Text('This is an example item.'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
authState.logout(); // Call logout method
|
||||
},
|
||||
label: const Text('Logout'),
|
||||
icon: const Icon(Icons.logout),
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user