feat(quick-add): save & add another for rapid manual entry
The quick-add sheet no longer closes on every save: a new 'Save & add another' action saves the seed, clears the form (keeping the chosen lot type), refocuses the name field and shows an 'N added' running count, so a whole shelf can be entered without reopening the sheet each time. Plain Save still closes it. Adds a dedicated label field with its own controller, submitAndAddAnother() on the cubit, and cubit + widget tests.
This commit is contained in:
parent
89b61bc9e4
commit
d3711e39b0
9 changed files with 240 additions and 18 deletions
|
|
@ -21,6 +21,7 @@ class QuickAddState extends Equatable {
|
|||
this.submitting = false,
|
||||
this.submitted = false,
|
||||
this.showLabelError = false,
|
||||
this.addedCount = 0,
|
||||
});
|
||||
|
||||
final String label;
|
||||
|
|
@ -32,6 +33,10 @@ class QuickAddState extends Equatable {
|
|||
final bool submitted;
|
||||
final bool showLabelError;
|
||||
|
||||
/// How many seeds this sheet has saved via "save & add another" (it stays
|
||||
/// open); drives the "N added" feedback and resets of the label field.
|
||||
final int addedCount;
|
||||
|
||||
bool get hasValidLabel => label.trim().isNotEmpty;
|
||||
|
||||
QuickAddState copyWith({
|
||||
|
|
@ -43,6 +48,7 @@ class QuickAddState extends Equatable {
|
|||
bool? submitting,
|
||||
bool? submitted,
|
||||
bool? showLabelError,
|
||||
int? addedCount,
|
||||
}) {
|
||||
return QuickAddState(
|
||||
label: label ?? this.label,
|
||||
|
|
@ -55,6 +61,7 @@ class QuickAddState extends Equatable {
|
|||
submitting: submitting ?? this.submitting,
|
||||
submitted: submitted ?? this.submitted,
|
||||
showLabelError: showLabelError ?? this.showLabelError,
|
||||
addedCount: addedCount ?? this.addedCount,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -68,6 +75,7 @@ class QuickAddState extends Equatable {
|
|||
submitting,
|
||||
submitted,
|
||||
showLabelError,
|
||||
addedCount,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -105,4 +113,23 @@ class QuickAddCubit extends Cubit<QuickAddState> {
|
|||
);
|
||||
emit(state.copyWith(submitting: false, submitted: true));
|
||||
}
|
||||
|
||||
/// Saves and keeps the sheet open for the next seed: resets the form to a
|
||||
/// clean state (keeping the chosen [lotType]) and bumps [addedCount]. Lets a
|
||||
/// user rip through a whole shelf without reopening the sheet each time.
|
||||
Future<void> submitAndAddAnother() async {
|
||||
if (!state.hasValidLabel) {
|
||||
emit(state.copyWith(showLabelError: true));
|
||||
return;
|
||||
}
|
||||
if (state.submitting) return;
|
||||
emit(state.copyWith(submitting: true));
|
||||
await _repo.addQuickVariety(
|
||||
label: state.label.trim(),
|
||||
lotType: state.lotType,
|
||||
quantity: state.quantity,
|
||||
photoBytes: state.photoBytes,
|
||||
);
|
||||
emit(QuickAddState(lotType: state.lotType, addedCount: state.addedCount + 1));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue