import 'package:e_scan/backend/api/api_calls.dart'; import 'package:e_scan/backend/schema/stock_picking/stock_picking_model.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 { 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({ StockPickingRecordModel? reception, @Default(false) bool loading, }) = _ReceptionDetailsPageState; }