mandreshope 28a8027e20 feat: Adds home page navigation drawer
Introduces a side navigation drawer on the home page to improve navigation and centralize user actions.

Displays the logged-in user's information (name, email) in the drawer header.
Adds a link to the Product List page ("Inventaire") within the drawer.
Moves the logout functionality to the drawer, ensuring user data is also cleared from local storage upon logout.
Ensures user data is saved to local storage during the login process and fetched when the home page loads.

Includes minor text updates on the Product Form page.
2025-07-03 15:04:30 +03:00

54 lines
1.4 KiB
Dart

import 'dart:convert';
import 'package:barcode_scanner/provider_container.dart';
import 'package:barcode_scanner/services/secure_storage.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'user_struct.freezed.dart';
part 'user_struct.g.dart';
@Freezed(toJson: true)
abstract class UserStruct with _$UserStruct {
factory UserStruct({
String? id,
String? firstName,
String? lastName,
String? email,
String? phone,
}) = _UserStruct;
factory UserStruct.fromJson(Map<String, dynamic> json) =>
_$UserStructFromJson(json);
}
extension UserStructExt on UserStruct {
String get key => 'user';
String get fullName {
final sb = StringBuffer();
sb.write(firstName);
if (firstName != null) {
sb.write(' ');
}
sb.write(lastName);
return sb.toString();
}
Future setToLocalStorage() {
final storage = providerContainer.read(sharedPrefsProvider);
return storage.write(key: id ?? key, value: jsonEncode(toJson()));
}
Future<UserStruct?> getFromLocalStorage() async {
final storage = providerContainer.read(sharedPrefsProvider);
final jsonString = await storage.read(key: id ?? key);
if (jsonString == null) return null;
return UserStruct.fromJson(jsonDecode(jsonString));
}
Future<void> deleteLocalStorage() {
final storage = providerContainer.read(sharedPrefsProvider);
return storage.delete(key: id ?? key);
}
}