feat: enhance category selection flow by adding preselection support and a select button

This commit is contained in:
Nils-Johan Gynther
2026-05-01 02:41:02 +02:00
parent 8bc1bd3e21
commit 4f387fe6eb
@@ -49,8 +49,17 @@ class CategoryThenProductPicker {
int? preselectedCategoryId, int? preselectedCategoryId,
Future<ProductOption?> Function(String name, int categoryId)? onCreate, Future<ProductOption?> Function(String name, int categoryId)? onCreate,
}) async { }) async {
// Steg 1 — välj kategori AdminCategoryNode? selectedCategory;
final selectedCategory = await showModalBottomSheet<AdminCategoryNode>(
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, context: context,
isScrollControlled: true, isScrollControlled: true,
useSafeArea: true, useSafeArea: true,
@@ -61,6 +70,7 @@ 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);
@@ -319,6 +329,16 @@ class _CategoryTileState extends State<_CategoryTile> {
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
), ),
trailing: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 8),
minimumSize: const Size(0, 32),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
visualDensity: VisualDensity.compact,
),
onPressed: () => widget.onLeafTap(node),
child: const Text('Välj'),
),
onTap: () => setState(() => _expanded = !_expanded), onTap: () => setState(() => _expanded = !_expanded),
), ),
if (_expanded) if (_expanded)