Skip to content

Commit

Permalink
feat: openfoodfacts#2470 - "add" taxonomized field improvements (open…
Browse files Browse the repository at this point in the history
…foodfacts#2477)

Impacted file:
* `simple_input_page.dart`: "add" button now trailing; comma separator handled; automatic inclusion of non-committed values
  • Loading branch information
monsieurtanuki authored Jul 2, 2022
1 parent f146928 commit 883792d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
if (widget.helper.getSubtitle(appLocalizations) != null)
Text(widget.helper.getSubtitle(appLocalizations)!),
ListTile(
onTap: () {
if (widget.helper.addTerm(_controller.text)) {
setState(() => _controller.text = '');
}
},
leading: const Icon(Icons.add_circle),
onTap: () => _addItemsFromController(),
trailing: const Icon(Icons.add_circle),
title: TextField(
decoration: InputDecoration(
filled: true,
Expand Down Expand Up @@ -142,6 +138,7 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
/// Parameter [saving] tells about the context: are we leaving the page,
/// or have we clicked on the "save" button?
Future<bool> _mayExitPage({required final bool saving}) async {
_addItemsFromController();
final Product? changedProduct = widget.helper.getChangedProduct();
if (changedProduct == null) {
return true;
Expand Down Expand Up @@ -179,4 +176,20 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
product: changedProduct,
);
}

/// Adds all the non-already existing items from the controller.
///
/// The item separator is the comma.
void _addItemsFromController() {
final List<String> input = _controller.text.split(',');
bool result = false;
for (final String item in input) {
if (widget.helper.addTerm(item.trim())) {
result = true;
}
}
if (result) {
setState(() => _controller.text = '');
}
}
}

0 comments on commit 883792d

Please sign in to comment.