63 lines
1.9 KiB
Dart
63 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:kmobile/data/repositories/auth_repository.dart';
|
|
import 'package:kmobile/features/profile/preferences/logout_dialog.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../../di/injection.dart';
|
|
import '../../l10n/app_localizations.dart';
|
|
import 'package:kmobile/features/profile/preferences/preference_screen.dart';
|
|
|
|
class ProfileScreen extends StatelessWidget {
|
|
const ProfileScreen({super.key});
|
|
|
|
|
|
Future<void> _handleLogout(BuildContext context) async {
|
|
final auth = getIt<AuthRepository>();
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.clear(); // clear saved session/token
|
|
await auth.clearAuthTokens();
|
|
// Navigate to login and remove all previous routes
|
|
Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final loc = AppLocalizations.of(context);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(loc.profile), // Localized "Profile"
|
|
),
|
|
body: ListView(
|
|
children: [
|
|
ListTile(
|
|
leading: const Icon(Icons.settings),
|
|
title: Text(loc.preferences),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const PreferenceScreen()),
|
|
);
|
|
},
|
|
),
|
|
// You can add more profile options here later
|
|
ListTile(
|
|
leading: const Icon(Icons.logout),
|
|
title: const Text("Logout"),
|
|
onTap: () async {
|
|
final shouldLogout = await showDialog<bool>(
|
|
context: context,
|
|
builder: (_) => const LogoutDialog(),
|
|
);
|
|
|
|
if (shouldLogout == true) {
|
|
await _handleLogout(context);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|