
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.
46 lines
1.4 KiB
Dart
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;
|
|
}
|