barcode_scanner/lib/pages/profile/profile_page_model.dart
mandreshope b1a4005235 feat: Adds user image field and profile page
Adds an `image` field to the user data structure to support profile pictures.

Introduces a new profile page and sets up navigation from the home screen.

Changes the product list page provider to auto dispose for improved resource management.
2025-07-04 12:17:13 +03:00

40 lines
1.4 KiB
Dart

import 'package:barcode_scanner/backend/objectbox/entities/product/product_entity.dart';
import 'package:barcode_scanner/backend/objectbox/objectbox_manager.dart';
import 'package:barcode_scanner/backend/schema/user/user_struct.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'profile_page_model.freezed.dart';
/// The provider for the AuthViewModel, using Riverpod's StateNotifierProvider
/// with autoDispose to manage the lifecycle of the view model.
final profilePageModelProvider =
StateNotifierProvider.autoDispose<ProfilePageModel, ProfilePageState>((
ref,
) {
return ProfilePageModel();
});
class ProfilePageModel extends StateNotifier<ProfilePageState> {
/// Constructor initializes the TaskRepository using the provider reference.
ProfilePageModel() : super(const ProfilePageState());
final productStore = objectboxManager.store.box<ProductEntity>();
Future getMe({Function(UserStruct? value)? onSuccess}) async {
state = state.copyWith(loading: true);
final me = await UserStruct(id: '1').getFromLocalStorage();
onSuccess?.call(me);
state = state.copyWith(user: me, loading: false);
}
}
@freezed
abstract class ProfilePageState with _$ProfilePageState {
const factory ProfilePageState({
UserStruct? user,
@Default(false) bool loading,
}) = _ProfilePageState;
}