refactor(category-picker): streamline category selection flow in product picker
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user