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:
soragui
2026-01-19 15:48:09 +08:00
parent fd5f38bd6f
commit 4d0207f41f
2 changed files with 43 additions and 3 deletions

View File

@@ -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();
}
}

View File

@@ -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,
);
}
}