From 883792d092e3f06627d38822b4f810d0f9d40997 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Sat, 2 Jul 2022 19:29:21 +0200 Subject: [PATCH] feat: #2470 - "add" taxonomized field improvements (#2477) Impacted file: * `simple_input_page.dart`: "add" button now trailing; comma separator handled; automatic inclusion of non-committed values --- .../lib/pages/product/simple_input_page.dart | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/smooth_app/lib/pages/product/simple_input_page.dart b/packages/smooth_app/lib/pages/product/simple_input_page.dart index 9ad765e55a4..35384af6169 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_page.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_page.dart @@ -63,12 +63,8 @@ class _SimpleInputPageState extends State { 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, @@ -142,6 +138,7 @@ class _SimpleInputPageState extends State { /// Parameter [saving] tells about the context: are we leaving the page, /// or have we clicked on the "save" button? Future _mayExitPage({required final bool saving}) async { + _addItemsFromController(); final Product? changedProduct = widget.helper.getChangedProduct(); if (changedProduct == null) { return true; @@ -179,4 +176,20 @@ class _SimpleInputPageState extends State { product: changedProduct, ); } + + /// Adds all the non-already existing items from the controller. + /// + /// The item separator is the comma. + void _addItemsFromController() { + final List 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 = ''); + } + } }