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, String? initialQuery,
Future<ProductOption?> Function(String name, int categoryId)? onCreate, Future<ProductOption?> Function(String name, int categoryId)? onCreate,
}) async { }) async {
AdminCategoryNode? selectedCategory; // Steg 1 — visa alltid kategoriträd (med eventuell förmarkering)
if (!context.mounted) return null;
if (preselectedCategoryId != null) { final selectedCategory = await showModalBottomSheet<AdminCategoryNode>(
// AI-föreslagen kategori — hoppa direkt till produktpickern context: context,
selectedCategory = _findNode(categoryTree, preselectedCategoryId); isScrollControlled: true,
} useSafeArea: true,
builder: (ctx) => _CategoryPickerSheet(
if (selectedCategory == null) { tree: categoryTree,
// Steg 1 — visa kategoriträd preselectedId: preselectedCategoryId,
if (!context.mounted) return null; onSelected: (node) => Navigator.pop(ctx, node),
selectedCategory = await showModalBottomSheet<AdminCategoryNode>( ),
context: context, );
isScrollControlled: true, if (selectedCategory == null || !context.mounted) return null;
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) // Samla alla kategori-IDs i den valda grenen (inkl. ättlingar)
final categoryIds = _collectIds(selectedCategory); final categoryIds = _collectIds(selectedCategory);
@@ -98,8 +89,8 @@ class CategoryThenProductPicker {
// Bygg eventuell onCreate-callback med categoryId inbunden // Bygg eventuell onCreate-callback med categoryId inbunden
final onCreateBound = onCreate == null final onCreateBound = onCreate == null
? null ? null
: (String name) => onCreate(name, selectedCategory!.id); : (String name) => onCreate(name, selectedCategory.id);
// Steg 2 — välj produkt // Steg 2 — välj produkt
if (!context.mounted) return null; if (!context.mounted) return null;