enhance: Optimizes backorder dialog and fixes loading state
Refactors the backorder dialog to use local Consumer widgets, reducing unnecessary rebuilds and improving performance. Corrects the loading state variable updated when confirming backorders, ensuring accurate UI feedback. Introduces a dedicated refresh method for receptions that includes a pre-sync, ensuring up-to-date data.
This commit is contained in:
parent
8c06ec7dad
commit
d131928235
@ -4,7 +4,7 @@ import 'package:e_scan/components/components.dart';
|
||||
import 'package:e_scan/themes/app_theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DeleteCategorieDialogComponentWidget extends ConsumerWidget {
|
||||
class DeleteCategorieDialogComponentWidget extends StatelessWidget {
|
||||
const DeleteCategorieDialogComponentWidget({
|
||||
super.key,
|
||||
required this.stockPickingId,
|
||||
@ -41,8 +41,7 @@ class DeleteCategorieDialogComponentWidget extends ConsumerWidget {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final state = ref.watch(receptionDetailsPageModelProvider);
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
@ -74,36 +73,54 @@ class DeleteCategorieDialogComponentWidget extends ConsumerWidget {
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Expanded(
|
||||
child: PrimaryButtonComponent(
|
||||
loading: state.withBackorderLoading,
|
||||
text: 'Créer un reliquat',
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(receptionDetailsPageModelProvider.notifier)
|
||||
.withBackorder(
|
||||
receptionId: stockPickingId,
|
||||
onSuccess: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
child: Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final state = ref.watch(
|
||||
receptionDetailsPageModelProvider,
|
||||
);
|
||||
return PrimaryButtonComponent(
|
||||
loading: state.withBackorderLoading,
|
||||
text: 'Créer un reliquat',
|
||||
onPressed: () {
|
||||
ref
|
||||
.read(
|
||||
receptionDetailsPageModelProvider.notifier,
|
||||
)
|
||||
.withBackorder(
|
||||
receptionId: stockPickingId,
|
||||
onSuccess: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: PrimaryButtonComponent(
|
||||
loading: state.withoutBackorderLoading,
|
||||
backgroundColor: Colors.red,
|
||||
text: 'Aucun reliquat',
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(receptionDetailsPageModelProvider.notifier)
|
||||
.withoutBackorder(
|
||||
receptionId: stockPickingId,
|
||||
onSuccess: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
// Navigator.pop(context);
|
||||
child: Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final state = ref.watch(
|
||||
receptionDetailsPageModelProvider,
|
||||
);
|
||||
return PrimaryButtonComponent(
|
||||
loading: state.withoutBackorderLoading,
|
||||
backgroundColor: Colors.red,
|
||||
text: 'Aucun reliquat',
|
||||
onPressed: () {
|
||||
ref
|
||||
.read(
|
||||
receptionDetailsPageModelProvider.notifier,
|
||||
)
|
||||
.withoutBackorder(
|
||||
receptionId: stockPickingId,
|
||||
onSuccess: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
// Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -152,7 +152,7 @@ class ReceptionDetailsPageModel
|
||||
final stockPickingRecords = objectboxManager.store
|
||||
.box<StockPickingRecordEntity>();
|
||||
final stockPikingEntity = stockPickingRecords.get(receptionId);
|
||||
state = state.copyWith(withBackorderLoading: true);
|
||||
state = state.copyWith(withoutBackorderLoading: true);
|
||||
final createBackorderConfirmationId =
|
||||
await ApiCalls.createBackorderConfirmation(
|
||||
stockPickingId: receptionId,
|
||||
@ -175,10 +175,10 @@ class ReceptionDetailsPageModel
|
||||
} else {
|
||||
onError?.call();
|
||||
}
|
||||
state = state.copyWith(withBackorderLoading: false);
|
||||
state = state.copyWith(withoutBackorderLoading: false);
|
||||
} catch (e) {
|
||||
onError?.call();
|
||||
state = state.copyWith(withBackorderLoading: false);
|
||||
state = state.copyWith(withoutBackorderLoading: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ class _ReceptionPageState extends ConsumerState<ReceptionPage> {
|
||||
receptionPageModelProvider
|
||||
.notifier,
|
||||
)
|
||||
.getAllReceptions(),
|
||||
.refreshReceptions(),
|
||||
);
|
||||
},
|
||||
child: StockPickingCard(
|
||||
|
@ -106,6 +106,24 @@ class ReceptionPageModel extends StateNotifier<ReceptionPageState> {
|
||||
state = state.copyWith(loadingReceptions: false);
|
||||
}
|
||||
}
|
||||
|
||||
Future refreshReceptions() async {
|
||||
// sync all data first
|
||||
await synchroAllData();
|
||||
try {
|
||||
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
|
||||
|
@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 0.2.2+7
|
||||
version: 0.2.3+8
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user