refactor: Streamlines stock picking data model

Refactors the `getAllStockPiking` API call to directly return a list of `StockPickingRecordModel`.

This change simplifies the data structure by removing the `StockPickingResponseModel` wrapper, making the `receptions` state in `ReceptionPageState` a direct, non-nullable list. It improves type safety and reduces verbose property access in the UI.
This commit is contained in:
mandreshope 2025-07-30 14:32:28 +03:00
parent e22a49f9bc
commit 1d15fd4d1c
4 changed files with 41 additions and 60 deletions

View File

@ -78,7 +78,7 @@ class ApiCalls {
}
}
static Future<Result<StockPickingResponseModel, Error>>
static Future<Result<List<StockPickingRecordModel>, Error>>
getAllStockPiking() async {
try {
if (!(await checkInternetConnexion())) {
@ -157,7 +157,9 @@ class ApiCalls {
if (response.statusCode == 200) {
final data = response.data;
if (data.containsKey('result')) {
return Result.success(StockPickingResponseModel.fromJson(data));
final result = StockPickingResponseModel.fromJson(data);
final records = result.result?.records ?? <StockPickingRecordModel>[];
return Result.success(records);
} else {
return Result.error(Error(data['error']));
}

View File

@ -62,22 +62,18 @@ class _ReceptionPageState extends ConsumerState<ReceptionPage> {
// context,
// ).bodyMedium.copyWith(fontWeight: FontWeight.bold),
// ),
state.receptions?.result?.records?.isEmpty == true
state.receptions.isEmpty == true
? Text('No data')
: ListView.builder(
physics: NeverScrollableScrollPhysics(),
primary: true,
shrinkWrap: true,
itemCount:
(state.receptions?.result?.records ??
<StockPickingRecordModel>[])
.length,
itemCount: state.receptions.length,
itemBuilder: (context, index) {
final reception =
state.receptions?.result?.records![index];
final reception = state.receptions[index];
return GestureDetector(
onTap: () {
final id = reception?.id;
final id = reception.id;
if (id == null) return;
ReceptionDetailsRoute(
receptionId: id,
@ -88,13 +84,13 @@ class _ReceptionPageState extends ConsumerState<ReceptionPage> {
horizontal: 5,
vertical: 5,
),
isDone: reception?.isDone == true,
reference: reception?.name ?? '',
from: reception?.locationId?.completeName,
to: reception?.locationDestId?.completeName,
contact: reception?.partnerId?.displayName,
origin: reception?.origin,
status: reception?.state,
isDone: reception.isDone == true,
reference: reception.name ?? '',
from: reception.locationId?.completeName,
to: reception.locationDestId?.completeName,
contact: reception.partnerId?.displayName,
origin: reception.origin,
status: reception.state,
),
);
},

View File

@ -1,5 +1,5 @@
import 'package:e_scan/backend/api/api_calls.dart';
import 'package:e_scan/backend/schema/stock_picking/stock_picking_model.dart';
import 'package:e_scan/backend/schema/stock_picking/stock_picking_record_model.dart';
import 'package:e_scan/backend/schema/user/user_struct.dart';
import 'package:e_scan/services/secure_storage.dart';
import 'package:e_scan/services/token_provider.dart';
@ -60,7 +60,8 @@ class ReceptionPageModel extends StateNotifier<ReceptionPageState> {
abstract class ReceptionPageState with _$ReceptionPageState {
const factory ReceptionPageState({
UserStruct? user,
StockPickingResponseModel? receptions,
@Default(<StockPickingRecordModel>[])
List<StockPickingRecordModel> receptions,
@Default(false) bool loadingReceptions,
@Default(false) bool loadingUser,
}) = _ReceptionPageState;

View File

@ -15,7 +15,7 @@ T _$identity<T>(T value) => value;
/// @nodoc
mixin _$ReceptionPageState implements DiagnosticableTreeMixin {
UserStruct? get user; StockPickingResponseModel? get receptions; bool get loadingReceptions; bool get loadingUser;
UserStruct? get user; List<StockPickingRecordModel> get receptions; bool get loadingReceptions; bool get loadingUser;
/// Create a copy of ReceptionPageState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@ -32,12 +32,12 @@ void debugFillProperties(DiagnosticPropertiesBuilder properties) {
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ReceptionPageState&&(identical(other.user, user) || other.user == user)&&(identical(other.receptions, receptions) || other.receptions == receptions)&&(identical(other.loadingReceptions, loadingReceptions) || other.loadingReceptions == loadingReceptions)&&(identical(other.loadingUser, loadingUser) || other.loadingUser == loadingUser));
return identical(this, other) || (other.runtimeType == runtimeType&&other is ReceptionPageState&&(identical(other.user, user) || other.user == user)&&const DeepCollectionEquality().equals(other.receptions, receptions)&&(identical(other.loadingReceptions, loadingReceptions) || other.loadingReceptions == loadingReceptions)&&(identical(other.loadingUser, loadingUser) || other.loadingUser == loadingUser));
}
@override
int get hashCode => Object.hash(runtimeType,user,receptions,loadingReceptions,loadingUser);
int get hashCode => Object.hash(runtimeType,user,const DeepCollectionEquality().hash(receptions),loadingReceptions,loadingUser);
@override
String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) {
@ -52,11 +52,11 @@ abstract mixin class $ReceptionPageStateCopyWith<$Res> {
factory $ReceptionPageStateCopyWith(ReceptionPageState value, $Res Function(ReceptionPageState) _then) = _$ReceptionPageStateCopyWithImpl;
@useResult
$Res call({
UserStruct? user, StockPickingResponseModel? receptions, bool loadingReceptions, bool loadingUser
UserStruct? user, List<StockPickingRecordModel> receptions, bool loadingReceptions, bool loadingUser
});
$UserStructCopyWith<$Res>? get user;$StockPickingResponseModelCopyWith<$Res>? get receptions;
$UserStructCopyWith<$Res>? get user;
}
/// @nodoc
@ -69,11 +69,11 @@ class _$ReceptionPageStateCopyWithImpl<$Res>
/// Create a copy of ReceptionPageState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? user = freezed,Object? receptions = freezed,Object? loadingReceptions = null,Object? loadingUser = null,}) {
@pragma('vm:prefer-inline') @override $Res call({Object? user = freezed,Object? receptions = null,Object? loadingReceptions = null,Object? loadingUser = null,}) {
return _then(_self.copyWith(
user: freezed == user ? _self.user : user // ignore: cast_nullable_to_non_nullable
as UserStruct?,receptions: freezed == receptions ? _self.receptions : receptions // ignore: cast_nullable_to_non_nullable
as StockPickingResponseModel?,loadingReceptions: null == loadingReceptions ? _self.loadingReceptions : loadingReceptions // ignore: cast_nullable_to_non_nullable
as UserStruct?,receptions: null == receptions ? _self.receptions : receptions // ignore: cast_nullable_to_non_nullable
as List<StockPickingRecordModel>,loadingReceptions: null == loadingReceptions ? _self.loadingReceptions : loadingReceptions // ignore: cast_nullable_to_non_nullable
as bool,loadingUser: null == loadingUser ? _self.loadingUser : loadingUser // ignore: cast_nullable_to_non_nullable
as bool,
));
@ -90,18 +90,6 @@ $UserStructCopyWith<$Res>? get user {
return $UserStructCopyWith<$Res>(_self.user!, (value) {
return _then(_self.copyWith(user: value));
});
}/// Create a copy of ReceptionPageState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$StockPickingResponseModelCopyWith<$Res>? get receptions {
if (_self.receptions == null) {
return null;
}
return $StockPickingResponseModelCopyWith<$Res>(_self.receptions!, (value) {
return _then(_self.copyWith(receptions: value));
});
}
}
@ -110,11 +98,17 @@ $StockPickingResponseModelCopyWith<$Res>? get receptions {
class _ReceptionPageState with DiagnosticableTreeMixin implements ReceptionPageState {
const _ReceptionPageState({this.user, this.receptions, this.loadingReceptions = false, this.loadingUser = false});
const _ReceptionPageState({this.user, final List<StockPickingRecordModel> receptions = const <StockPickingRecordModel>[], this.loadingReceptions = false, this.loadingUser = false}): _receptions = receptions;
@override final UserStruct? user;
@override final StockPickingResponseModel? receptions;
final List<StockPickingRecordModel> _receptions;
@override@JsonKey() List<StockPickingRecordModel> get receptions {
if (_receptions is EqualUnmodifiableListView) return _receptions;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_receptions);
}
@override@JsonKey() final bool loadingReceptions;
@override@JsonKey() final bool loadingUser;
@ -134,12 +128,12 @@ void debugFillProperties(DiagnosticPropertiesBuilder properties) {
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ReceptionPageState&&(identical(other.user, user) || other.user == user)&&(identical(other.receptions, receptions) || other.receptions == receptions)&&(identical(other.loadingReceptions, loadingReceptions) || other.loadingReceptions == loadingReceptions)&&(identical(other.loadingUser, loadingUser) || other.loadingUser == loadingUser));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ReceptionPageState&&(identical(other.user, user) || other.user == user)&&const DeepCollectionEquality().equals(other._receptions, _receptions)&&(identical(other.loadingReceptions, loadingReceptions) || other.loadingReceptions == loadingReceptions)&&(identical(other.loadingUser, loadingUser) || other.loadingUser == loadingUser));
}
@override
int get hashCode => Object.hash(runtimeType,user,receptions,loadingReceptions,loadingUser);
int get hashCode => Object.hash(runtimeType,user,const DeepCollectionEquality().hash(_receptions),loadingReceptions,loadingUser);
@override
String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) {
@ -154,11 +148,11 @@ abstract mixin class _$ReceptionPageStateCopyWith<$Res> implements $ReceptionPag
factory _$ReceptionPageStateCopyWith(_ReceptionPageState value, $Res Function(_ReceptionPageState) _then) = __$ReceptionPageStateCopyWithImpl;
@override @useResult
$Res call({
UserStruct? user, StockPickingResponseModel? receptions, bool loadingReceptions, bool loadingUser
UserStruct? user, List<StockPickingRecordModel> receptions, bool loadingReceptions, bool loadingUser
});
@override $UserStructCopyWith<$Res>? get user;@override $StockPickingResponseModelCopyWith<$Res>? get receptions;
@override $UserStructCopyWith<$Res>? get user;
}
/// @nodoc
@ -171,11 +165,11 @@ class __$ReceptionPageStateCopyWithImpl<$Res>
/// Create a copy of ReceptionPageState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? user = freezed,Object? receptions = freezed,Object? loadingReceptions = null,Object? loadingUser = null,}) {
@override @pragma('vm:prefer-inline') $Res call({Object? user = freezed,Object? receptions = null,Object? loadingReceptions = null,Object? loadingUser = null,}) {
return _then(_ReceptionPageState(
user: freezed == user ? _self.user : user // ignore: cast_nullable_to_non_nullable
as UserStruct?,receptions: freezed == receptions ? _self.receptions : receptions // ignore: cast_nullable_to_non_nullable
as StockPickingResponseModel?,loadingReceptions: null == loadingReceptions ? _self.loadingReceptions : loadingReceptions // ignore: cast_nullable_to_non_nullable
as UserStruct?,receptions: null == receptions ? _self._receptions : receptions // ignore: cast_nullable_to_non_nullable
as List<StockPickingRecordModel>,loadingReceptions: null == loadingReceptions ? _self.loadingReceptions : loadingReceptions // ignore: cast_nullable_to_non_nullable
as bool,loadingUser: null == loadingUser ? _self.loadingUser : loadingUser // ignore: cast_nullable_to_non_nullable
as bool,
));
@ -193,18 +187,6 @@ $UserStructCopyWith<$Res>? get user {
return $UserStructCopyWith<$Res>(_self.user!, (value) {
return _then(_self.copyWith(user: value));
});
}/// Create a copy of ReceptionPageState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$StockPickingResponseModelCopyWith<$Res>? get receptions {
if (_self.receptions == null) {
return null;
}
return $StockPickingResponseModelCopyWith<$Res>(_self.receptions!, (value) {
return _then(_self.copyWith(receptions: value));
});
}
}