refactor(category-picker): streamline category selection flow in product picker

This commit is contained in:
Nils-Johan Gynther
2026-05-03 14:01:28 +02:00
parent 98e065a3e2
commit 3bfcf63a53
@@ -64,28 +64,19 @@ class CategoryThenProductPicker {
String? initialQuery,
Future<ProductOption?> 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<AdminCategoryNode>(
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<AdminCategoryNode>(
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;