barcode_scanner/lib/pages/operation/reception/reception_page_model.dart
mandreshope 8252cf0b22 feat: Adds stock picking detail view and API call
Implements a dedicated page for viewing detailed stock picking information.

- Introduces `getStockPikingById` API call to fetch a single stock picking record by ID.
- Enhances `MainAppbarComponent` to support customizable leading widgets, enabling a back button on detail pages.
- Improves `QuickActionComponent` by allowing optional `onTap` callbacks for actions, making buttons conditionally visible and reusable across different contexts.
- Adds `margin` property to `StockPickingCard` for flexible layout adjustments.
- Refactors `ReceptionDetailsPage` to utilize the new API call and display a single stock picking's details, adapting its app bar and quick actions accordingly.
2025-07-29 14:43:43 +03:00

68 lines
2.2 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> {
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;
}