refactor(category-picker): streamline category selection flow in product picker
This commit is contained in:
@@ -64,17 +64,9 @@ 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 (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;
|
if (!context.mounted) return null;
|
||||||
selectedCategory = await showModalBottomSheet<AdminCategoryNode>(
|
final selectedCategory = await showModalBottomSheet<AdminCategoryNode>(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
useSafeArea: true,
|
useSafeArea: true,
|
||||||
@@ -85,7 +77,6 @@ class CategoryThenProductPicker {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (selectedCategory == null || !context.mounted) return null;
|
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);
|
||||||
@@ -99,7 +90,7 @@ 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user