From ccbe094d2374be75fa0343b911dff374e2279b00 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Fri, 25 Oct 2024 08:03:20 +0200 Subject: [PATCH] fix: 5627 - remove focus from price amount after adding product (#5729) --- .../pages/prices/price_add_product_card.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/smooth_app/lib/pages/prices/price_add_product_card.dart b/packages/smooth_app/lib/pages/prices/price_add_product_card.dart index fd1930d32d4..12e8cec788b 100644 --- a/packages/smooth_app/lib/pages/prices/price_add_product_card.dart +++ b/packages/smooth_app/lib/pages/prices/price_add_product_card.dart @@ -24,6 +24,17 @@ class _PriceAddProductCardState extends State { String? _latestScannedBarcode; + // we create dummy focus nodes to focus on, when we need to unfocus. + final List _dummyFocusNodes = []; + + @override + void dispose() { + for (final FocusNode focusNode in _dummyFocusNodes) { + focusNode.dispose(); + } + super.dispose(); + } + @override Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context); @@ -109,6 +120,13 @@ class _PriceAddProductCardState extends State { ), ), ); + + // unfocus from the previous price amount text field. + // looks like the most efficient way to unfocus: focus somewhere in space... + final FocusNode focusNode = FocusNode(); + _dummyFocusNodes.add(focusNode); + FocusScope.of(context).requestFocus(focusNode); + priceModel.notifyListeners(); }