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_scan_page_model.freezed.dart'; final receptionScanPageModelProvider = StateNotifierProvider.autoDispose< ReceptionScanPageModel, ReceptionScanPageModelState >((ref) { return ReceptionScanPageModel(); }); class ReceptionScanPageModel extends StateNotifier { ReceptionScanPageModel() : super(const ReceptionScanPageModelState()); 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 ReceptionScanPageModelState with _$ReceptionScanPageModelState { const factory ReceptionScanPageModelState({ StockPickingRecordEntity? reception, @Default(false) bool loading, }) = _ReceptionScanPageModelState; }