From 3bfcf63a53d89d3161fe3d23fe1de4afbe1ac507 Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Sun, 3 May 2026 14:01:28 +0200 Subject: [PATCH] refactor(category-picker): streamline category selection flow in product picker --- .../core/ui/category_then_product_picker.dart | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/flutter/lib/core/ui/category_then_product_picker.dart b/flutter/lib/core/ui/category_then_product_picker.dart index 21a32760..06544430 100644 --- a/flutter/lib/core/ui/category_then_product_picker.dart +++ b/flutter/lib/core/ui/category_then_product_picker.dart @@ -64,28 +64,19 @@ class CategoryThenProductPicker { String? initialQuery, Future Function(String name, int categoryId)? onCreate, }) async { - AdminCategoryNode? selectedCategory; - - if (preselectedCategoryId != null) { - // AI-föreslagen kategori — hoppa direkt till produktpickern - selectedCategory = _findNode(categoryTree, preselectedCategoryId); - } - - if (selectedCategory == null) { - // Steg 1 — visa kategoriträd - if (!context.mounted) return null; - selectedCategory = await showModalBottomSheet( - context: context, - isScrollControlled: true, - useSafeArea: true, - builder: (ctx) => _CategoryPickerSheet( - tree: categoryTree, - preselectedId: preselectedCategoryId, - onSelected: (node) => Navigator.pop(ctx, node), - ), - ); - if (selectedCategory == null || !context.mounted) return null; - } + // Steg 1 — visa alltid kategoriträd (med eventuell förmarkering) + if (!context.mounted) return null; + final selectedCategory = await showModalBottomSheet( + context: context, + isScrollControlled: true, + useSafeArea: true, + builder: (ctx) => _CategoryPickerSheet( + tree: categoryTree, + preselectedId: preselectedCategoryId, + onSelected: (node) => Navigator.pop(ctx, node), + ), + ); + if (selectedCategory == null || !context.mounted) return null; // Samla alla kategori-IDs i den valda grenen (inkl. ättlingar) final categoryIds = _collectIds(selectedCategory); @@ -98,8 +89,8 @@ class CategoryThenProductPicker { // Bygg eventuell onCreate-callback med categoryId inbunden final onCreateBound = onCreate == null - ? null - : (String name) => onCreate(name, selectedCategory!.id); + ? null + : (String name) => onCreate(name, selectedCategory.id); // Steg 2 — välj produkt if (!context.mounted) return null;