
Fetches and displays a list of recent stock reception operations on the reception page. Introduces a new `StockPickingCard` component to present each reception record clearly and consistently. The `ReceptionPageModel` now automatically fetches reception data upon initialization. Provides visual feedback for loading states and when no reception data is available, enhancing the user's overview of recent activities.
69 lines
2.3 KiB
Dart
69 lines
2.3 KiB
Dart
import 'package:barcode_scanner/backend/api/api_calls.dart';
|
|
import 'package:barcode_scanner/backend/schema/stock_picking/stock_picking_model.dart';
|
|
import 'package:barcode_scanner/backend/schema/user/user_struct.dart';
|
|
import 'package:barcode_scanner/services/secure_storage.dart';
|
|
import 'package:barcode_scanner/services/token_provider.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'reception_page_model.freezed.dart';
|
|
|
|
final receptionPageModelProvider =
|
|
StateNotifierProvider<ReceptionPageModel, ReceptionPageState>((ref) {
|
|
return ReceptionPageModel(
|
|
secureStorage: ref.read(sharedPrefsProvider),
|
|
tokenProvider: ref.read(tokenProvider),
|
|
userConnectedProvider: ref.read(userConnectedProvider),
|
|
);
|
|
});
|
|
|
|
class ReceptionPageModel extends StateNotifier<ReceptionPageState> {
|
|
/// Constructor initializes the TaskRepository using the provider reference.
|
|
ReceptionPageModel({
|
|
required this.secureStorage,
|
|
required this.tokenProvider,
|
|
required this.userConnectedProvider,
|
|
}) : super(const ReceptionPageState()) {
|
|
getAllReceptions();
|
|
}
|
|
|
|
late FlutterSecureStorage secureStorage;
|
|
late TokenProvider tokenProvider;
|
|
final UserConnectedProvider userConnectedProvider;
|
|
|
|
Future getUserConnected() async {
|
|
state = state.copyWith(loadingUser: true);
|
|
final user = await userConnectedProvider.get();
|
|
state = state.copyWith(user: user, loadingUser: false);
|
|
}
|
|
|
|
Future getAllReceptions() async {
|
|
try {
|
|
state = state.copyWith(loadingReceptions: true);
|
|
final res = await ApiCalls.getAllStockPiking();
|
|
res.when(
|
|
(data) {
|
|
state = state.copyWith(receptions: data, loadingReceptions: false);
|
|
},
|
|
(error) {
|
|
state = state.copyWith(loadingReceptions: false);
|
|
},
|
|
);
|
|
} catch (e) {
|
|
state = state.copyWith(loadingReceptions: false);
|
|
}
|
|
}
|
|
}
|
|
|
|
@freezed
|
|
abstract class ReceptionPageState with _$ReceptionPageState {
|
|
const factory ReceptionPageState({
|
|
UserStruct? user,
|
|
StockPickingResponseModel? receptions,
|
|
@Default(false) bool loadingReceptions,
|
|
@Default(false) bool loadingUser,
|
|
}) = _ReceptionPageState;
|
|
}
|