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
|
|
@ -49,22 +49,7 @@ class QuickAddSheet extends StatelessWidget {
|
|||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
key: const Key('quickAdd.labelField'),
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.done,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.quickAdd.labelField,
|
||||
errorText: state.showLabelError
|
||||
? t.quickAdd.labelRequired
|
||||
: null,
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
),
|
||||
onChanged: cubit.labelChanged,
|
||||
onSubmitted: (_) => cubit.submit(),
|
||||
),
|
||||
const _LabelField(),
|
||||
const SizedBox(height: 16),
|
||||
LotTypeSelector(
|
||||
value: state.lotType,
|
||||
|
|
@ -104,7 +89,22 @@ class QuickAddSheet extends StatelessWidget {
|
|||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(t.quickAdd.cancel),
|
||||
),
|
||||
if (state.addedCount > 0) ...[
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
t.quickAdd.addedCount(n: state.addedCount),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
key: const Key('quickAdd.saveAndAddAnother'),
|
||||
onPressed: state.submitting
|
||||
? null
|
||||
: cubit.submitAndAddAnother,
|
||||
child: Text(t.quickAdd.saveAndAddAnother),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
FilledButton(
|
||||
key: const Key('quickAdd.save'),
|
||||
onPressed: state.submitting ? null : cubit.submit,
|
||||
|
|
@ -121,6 +121,60 @@ class QuickAddSheet extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
/// The name field, with its own controller so "save & add another" can clear
|
||||
/// it and refocus without tearing down the sheet.
|
||||
class _LabelField extends StatefulWidget {
|
||||
const _LabelField();
|
||||
|
||||
@override
|
||||
State<_LabelField> createState() => _LabelFieldState();
|
||||
}
|
||||
|
||||
class _LabelFieldState extends State<_LabelField> {
|
||||
final _controller = TextEditingController();
|
||||
final _focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final t = context.t;
|
||||
final cubit = context.read<QuickAddCubit>();
|
||||
return BlocListener<QuickAddCubit, QuickAddState>(
|
||||
listenWhen: (prev, curr) => prev.addedCount != curr.addedCount,
|
||||
listener: (context, _) {
|
||||
_controller.clear();
|
||||
_focusNode.requestFocus();
|
||||
},
|
||||
child: BlocBuilder<QuickAddCubit, QuickAddState>(
|
||||
buildWhen: (prev, curr) => prev.showLabelError != curr.showLabelError,
|
||||
builder: (context, state) => TextField(
|
||||
key: const Key('quickAdd.labelField'),
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.done,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.quickAdd.labelField,
|
||||
errorText: state.showLabelError ? t.quickAdd.labelRequired : null,
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
),
|
||||
onChanged: cubit.labelChanged,
|
||||
onSubmitted: (_) => cubit.submit(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MoreSection extends StatelessWidget {
|
||||
const _MoreSection();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue