barcode_scanner/lib/pages/operation/reception/reception_details_page_model.dart
mandreshope 9dad7f9d9f feat: Integrates ObjectBox for stock picking persistence
Enables offline capabilities and improved data access for stock picking records.
API calls now prioritize local ObjectBox storage when offline and persist fetched data upon successful remote retrieval.
Introduces comprehensive model-to-entity conversion logic for stock picking data and its related models.
Updates UI components and state management to directly consume ObjectBox entities, optimizing data display and interaction.
Adjusts ObjectBox entity schema for improved flexibility and adds utility getters.
2025-07-30 15:38:26 +03:00

46 lines
1.4 KiB
Dart

import 'package:e_scan/backend/api/api_calls.dart';
import 'package:e_scan/backend/objectbox/entities/stock_picking/stock_picking_record_entity.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'reception_details_page_model.freezed.dart';
final receptionDetailsPageModelProvider =
StateNotifierProvider.autoDispose<
ReceptionDetailsPageModel,
ReceptionDetailsPageState
>((ref) {
return ReceptionDetailsPageModel();
});
class ReceptionDetailsPageModel
extends StateNotifier<ReceptionDetailsPageState> {
ReceptionDetailsPageModel() : super(const ReceptionDetailsPageState());
Future getReceptionById({required int id}) async {
try {
state = state.copyWith(loading: true);
final res = await ApiCalls.getStockPikingById(id: id);
res.when(
(data) {
state = state.copyWith(loading: false, reception: data);
},
(error) {
state = state.copyWith(loading: false);
},
);
} catch (e) {
state = state.copyWith(loading: false);
}
}
}
@freezed
abstract class ReceptionDetailsPageState with _$ReceptionDetailsPageState {
const factory ReceptionDetailsPageState({
StockPickingRecordEntity? reception,
@Default(false) bool loading,
}) = _ReceptionDetailsPageState;
}