feat: Adds logout functionality
Adds a logout button to the home page app bar. Implements the logout logic in the login page model, clearing the stored user token. Navigates to the splash screen after logout to handle redirection based on the updated authentication state.
This commit is contained in:
parent
56ca49d84e
commit
b705142d48
@ -1,3 +1,5 @@
|
||||
import 'package:barcode_scanner/pages/login_page/login_page_model.dart';
|
||||
import 'package:barcode_scanner/router/go_router_builder.dart';
|
||||
import 'package:barcode_scanner/router/go_secure_router_builder.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@ -15,6 +17,21 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
final primaryColor = Theme.of(context).primaryColor;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
automaticallyImplyLeading: false,
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await ref.read(loginPageModelProvider.notifier).logOut();
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
SplashRoute().go(context);
|
||||
});
|
||||
},
|
||||
icon: Icon(Icons.login),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
|
@ -91,6 +91,11 @@ class LoginPageModel extends StateNotifier<LoginPageState> {
|
||||
SplashRoute().go(context);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> logOut() async {
|
||||
await secureStorage.delete(key: TokenProvider.tokenKey);
|
||||
await checkHasUserConnected();
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
|
Loading…
x
Reference in New Issue
Block a user