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:e_scan/themes/app_theme.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class DeleteCategorieDialogComponentWidget extends ConsumerWidget {
|
class DeleteCategorieDialogComponentWidget extends StatelessWidget {
|
||||||
const DeleteCategorieDialogComponentWidget({
|
const DeleteCategorieDialogComponentWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.stockPickingId,
|
required this.stockPickingId,
|
||||||
@ -41,8 +41,7 @@ class DeleteCategorieDialogComponentWidget extends ConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context) {
|
||||||
final state = ref.watch(receptionDetailsPageModelProvider);
|
|
||||||
return Container(
|
return Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -74,36 +73,54 @@ class DeleteCategorieDialogComponentWidget extends ConsumerWidget {
|
|||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PrimaryButtonComponent(
|
child: Consumer(
|
||||||
loading: state.withBackorderLoading,
|
builder: (context, ref, child) {
|
||||||
text: 'Créer un reliquat',
|
final state = ref.watch(
|
||||||
onPressed: () async {
|
receptionDetailsPageModelProvider,
|
||||||
await ref
|
);
|
||||||
.read(receptionDetailsPageModelProvider.notifier)
|
return PrimaryButtonComponent(
|
||||||
.withBackorder(
|
loading: state.withBackorderLoading,
|
||||||
receptionId: stockPickingId,
|
text: 'Créer un reliquat',
|
||||||
onSuccess: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
ref
|
||||||
},
|
.read(
|
||||||
);
|
receptionDetailsPageModelProvider.notifier,
|
||||||
|
)
|
||||||
|
.withBackorder(
|
||||||
|
receptionId: stockPickingId,
|
||||||
|
onSuccess: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PrimaryButtonComponent(
|
child: Consumer(
|
||||||
loading: state.withoutBackorderLoading,
|
builder: (context, ref, child) {
|
||||||
backgroundColor: Colors.red,
|
final state = ref.watch(
|
||||||
text: 'Aucun reliquat',
|
receptionDetailsPageModelProvider,
|
||||||
onPressed: () async {
|
);
|
||||||
await ref
|
return PrimaryButtonComponent(
|
||||||
.read(receptionDetailsPageModelProvider.notifier)
|
loading: state.withoutBackorderLoading,
|
||||||
.withoutBackorder(
|
backgroundColor: Colors.red,
|
||||||
receptionId: stockPickingId,
|
text: 'Aucun reliquat',
|
||||||
onSuccess: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
ref
|
||||||
},
|
.read(
|
||||||
);
|
receptionDetailsPageModelProvider.notifier,
|
||||||
// Navigator.pop(context);
|
)
|
||||||
|
.withoutBackorder(
|
||||||
|
receptionId: stockPickingId,
|
||||||
|
onSuccess: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
// Navigator.pop(context);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -152,7 +152,7 @@ class ReceptionDetailsPageModel
|
|||||||
final stockPickingRecords = objectboxManager.store
|
final stockPickingRecords = objectboxManager.store
|
||||||
.box<StockPickingRecordEntity>();
|
.box<StockPickingRecordEntity>();
|
||||||
final stockPikingEntity = stockPickingRecords.get(receptionId);
|
final stockPikingEntity = stockPickingRecords.get(receptionId);
|
||||||
state = state.copyWith(withBackorderLoading: true);
|
state = state.copyWith(withoutBackorderLoading: true);
|
||||||
final createBackorderConfirmationId =
|
final createBackorderConfirmationId =
|
||||||
await ApiCalls.createBackorderConfirmation(
|
await ApiCalls.createBackorderConfirmation(
|
||||||
stockPickingId: receptionId,
|
stockPickingId: receptionId,
|
||||||
@ -175,10 +175,10 @@ class ReceptionDetailsPageModel
|
|||||||
} else {
|
} else {
|
||||||
onError?.call();
|
onError?.call();
|
||||||
}
|
}
|
||||||
state = state.copyWith(withBackorderLoading: false);
|
state = state.copyWith(withoutBackorderLoading: false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onError?.call();
|
onError?.call();
|
||||||
state = state.copyWith(withBackorderLoading: false);
|
state = state.copyWith(withoutBackorderLoading: false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class _ReceptionPageState extends ConsumerState<ReceptionPage> {
|
|||||||
receptionPageModelProvider
|
receptionPageModelProvider
|
||||||
.notifier,
|
.notifier,
|
||||||
)
|
)
|
||||||
.getAllReceptions(),
|
.refreshReceptions(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: StockPickingCard(
|
child: StockPickingCard(
|
||||||
|
@ -106,6 +106,24 @@ class ReceptionPageModel extends StateNotifier<ReceptionPageState> {
|
|||||||
state = state.copyWith(loadingReceptions: false);
|
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
|
@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
|
# 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
|
# 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.
|
# 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:
|
environment:
|
||||||
sdk: ^3.8.1
|
sdk: ^3.8.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user